diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 73f5f543442ce348bb15e9ba4ad2907e2c510b3d..8fad4c27261745c47868b7a4a8396e6f6b18140b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,7 @@ stages: - builds - tests + - fmt before_script: - export PATH="$HOME/.cargo/bin:$PATH" @@ -18,3 +19,13 @@ tests: - redshift-rs script: - cargo test + +fmt: + stage: fmt + tags: + - redshift-rs-nightly + before_script: + - export PATH="$HOME/.cargo/bin:$PATH" + - cargo install --force rustfmt-nightly + script: + - cargo fmt -- --write-mode=diff diff --git a/wotb/lib.rs b/wotb/lib.rs index 1291b619b4f299c39c820aef7a9ec2da2010b729..e2f7330b8c12b0a3aa008c245d94a57405d41442 100644 --- a/wotb/lib.rs +++ b/wotb/lib.rs @@ -23,17 +23,14 @@ //! [Duniter]: https://duniter.org/ //! [js-tests]: https://github.com/duniter/wotb/blob/master/wotcpp/webOfTrust.cpp -#![deny(missing_docs, - missing_debug_implementations, missing_copy_implementations, - trivial_casts, trivial_numeric_casts, - unsafe_code, - unstable_features, - unused_import_braces, unused_qualifications)] +#![deny(missing_docs, missing_debug_implementations, missing_copy_implementations, trivial_casts, + trivial_numeric_casts, unsafe_code, unstable_features, unused_import_braces, + unused_qualifications)] +extern crate bincode; extern crate serde; #[macro_use] extern crate serde_derive; -extern crate bincode; use std::collections::HashSet; use std::collections::hash_set::Iter; @@ -41,7 +38,7 @@ use std::rc::Rc; use std::fs::File; use std::io::prelude::*; -use bincode::{serialize, deserialize, Infinite}; +use bincode::{deserialize, serialize, Infinite}; /// Wrapper for a node id. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] @@ -286,9 +283,7 @@ impl WebOfTrust { let mut sentries: Vec<bool> = self.nodes .iter() - .map(|x| { - x.enabled && x.issued_count() >= d_min && x.links_iter().count() >= d_min - }) + .map(|x| x.enabled && x.issued_count() >= d_min && x.links_iter().count() >= d_min) .collect(); sentries[member.0] = false; @@ -318,9 +313,7 @@ impl WebOfTrust { pub fn get_sentries(&self, d_min: usize) -> Vec<NodeId> { self.nodes .iter() - .filter(|x| { - x.enabled && x.issued_count() >= d_min && x.links_iter().count() >= d_min - }) + .filter(|x| x.enabled && x.issued_count() >= d_min && x.links_iter().count() >= d_min) .map(|x| x.id()) .collect() } @@ -329,9 +322,7 @@ impl WebOfTrust { pub fn get_non_sentries(&self, d_min: usize) -> Vec<NodeId> { self.nodes .iter() - .filter(|x| { - x.enabled && (x.issued_count < d_min || x.links_iter().count() < d_min) - }) + .filter(|x| x.enabled && (x.issued_count < d_min || x.links_iter().count() < d_min)) .map(|x| x.id()) .collect() } @@ -818,6 +809,5 @@ mod tests { wot2.get_non_sentries(1).len() ); } - } }