diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 64430191..27f5eaa6 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -10,6 +10,10 @@ jobs: - name: install rustc run: | sudo apt install rustc + - name: format + run: | + cd rust + cargo fmt -- --check - name: compile run: | cd rust diff --git a/rust/combinatorics/permutations.rs b/rust/combinatorics/permutations.rs index 0ff817e2..79018b67 100644 --- a/rust/combinatorics/permutations.rs +++ b/rust/combinatorics/permutations.rs @@ -8,8 +8,8 @@ pub fn next_permutation(p: &mut [usize]) -> Option<()> { #[cfg(test)] mod tests { - use rstest::rstest; use crate::next_permutation; + use rstest::rstest; #[rstest] #[case(vec![0], vec![0], None)] diff --git a/rust/graphs/shortestpaths/dijkstra.rs b/rust/graphs/shortestpaths/dijkstra.rs index 5a7e06dd..5bcc4b35 100644 --- a/rust/graphs/shortestpaths/dijkstra.rs +++ b/rust/graphs/shortestpaths/dijkstra.rs @@ -10,7 +10,9 @@ pub fn dijkstra_heap(graph: &[Vec<(usize, i32)>], s: usize) -> (Vec, Vec nprio { diff --git a/rust/misc/binary_search.rs b/rust/misc/binary_search.rs index f72281e1..ed1bb9d4 100644 --- a/rust/misc/binary_search.rs +++ b/rust/misc/binary_search.rs @@ -18,18 +18,15 @@ where #[cfg(test)] mod tests { - use rstest::rstest; use crate::binary_search_first_true; + use rstest::rstest; #[rstest] #[case(100, 0)] #[case(100, 1)] #[case(100, 50)] #[case(100, 100)] - fn basic_test( - #[case] n: i32, - #[case] pos: i32, - ) { + fn basic_test(#[case] n: i32, #[case] pos: i32) { assert_eq!(binary_search_first_true(|i| { i >= pos }, 0, n), pos); } } diff --git a/rust/structures/disjoint_sets.rs b/rust/structures/disjoint_sets.rs index 95adb2e8..0bdcfa03 100644 --- a/rust/structures/disjoint_sets.rs +++ b/rust/structures/disjoint_sets.rs @@ -1,10 +1,12 @@ struct DisjointSets { - p: Vec + p: Vec, } impl DisjointSets { pub fn new(n: usize) -> Self { - DisjointSets { p: (0..n).collect() } + DisjointSets { + p: (0..n).collect(), + } } pub fn root(&mut self, x: usize) -> usize { diff --git a/rust/structures/fenwick_tree.rs b/rust/structures/fenwick_tree.rs index 45030202..883e8b04 100644 --- a/rust/structures/fenwick_tree.rs +++ b/rust/structures/fenwick_tree.rs @@ -1,12 +1,14 @@ use std::ops::AddAssign; struct Fenwick { - t: Vec + t: Vec, } impl> Fenwick { fn new(n: usize) -> Self { - Fenwick { t: vec![0.into(); n] } + Fenwick { + t: vec![0.into(); n], + } } pub fn add(&mut self, mut i: usize, value: T) { diff --git a/rust/structures/persistent_tree.rs b/rust/structures/persistent_tree.rs index 1f18f6a3..5a550e7c 100644 --- a/rust/structures/persistent_tree.rs +++ b/rust/structures/persistent_tree.rs @@ -54,9 +54,15 @@ impl PersistentTree { } else { let mid = (left + right) >> 1; if pos <= mid { - Node::new_parent(&Self::set(pos, value, root.left.as_ref().unwrap(), left, mid), root.right.as_ref().unwrap()) + Node::new_parent( + &Self::set(pos, value, root.left.as_ref().unwrap(), left, mid), + root.right.as_ref().unwrap(), + ) } else { - Node::new_parent(root.left.as_ref().unwrap(), &Self::set(pos, value, root.right.as_ref().unwrap(), mid + 1, right)) + Node::new_parent( + root.left.as_ref().unwrap(), + &Self::set(pos, value, root.right.as_ref().unwrap(), mid + 1, right), + ) } }; Rc::new(node)