diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f520b42..c2001d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,6 +19,8 @@ jobs: - nightly steps: - uses: actions/checkout@v3 - - run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} + - run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} && rustup component add clippy && rustup component add rustfmt - run: cargo build --verbose - run: cargo test --verbose + - run: cargo clippy --all-features -- -D warnings + - run: cargo fmt --check diff --git a/src/avl.rs b/src/avl.rs index 6962a9c..dd9e7ee 100644 --- a/src/avl.rs +++ b/src/avl.rs @@ -45,13 +45,10 @@ impl AVL { impl AVL { pub fn empty() -> AVL { - return AVL::Empty; + AVL::Empty } pub fn is_empty(&self) -> bool { - match self { - AVL::Empty => true, - _ => false, - } + matches!(self, AVL::Empty) } fn height(&self) -> i64 { match self { @@ -72,7 +69,7 @@ impl AVL { value: _, left, right, - } => &left.height() - &right.height(), + } => left.height() - right.height(), } } pub fn find(&self, target_value: &K) -> Option<&V> { @@ -118,7 +115,7 @@ impl AVL { }; } } - return self.clone(); + self.clone() } fn right_fix(&self) -> AVL { if let AVL::Node { @@ -140,7 +137,7 @@ impl AVL { return self.right_rotation(); } } - return self.clone(); + self.clone() } fn left_rotation(&self) -> AVL { if let AVL::Node { @@ -170,7 +167,7 @@ impl AVL { }; } } - return self.clone(); + self.clone() } fn left_fix(&self) -> AVL { if let AVL::Node { @@ -192,7 +189,7 @@ impl AVL { return self.left_rotation(); } } - return self.clone(); + self.clone() } fn fix(&self) -> AVL { match self.diff() { diff --git a/src/list.rs b/src/list.rs index 14504d2..baa90c9 100644 --- a/src/list.rs +++ b/src/list.rs @@ -94,10 +94,10 @@ impl List { } } pub fn empty() -> List { - return List { + List { head: RefCounter::new(ListNode::Empty), len: 0, - }; + } } fn push_front_rc(&self, rc_value: RefCounter) -> List { List { @@ -163,7 +163,7 @@ mod tests { .push_front(3) .push_front(2) .push_front(1); - let v = vec![1, 2, 3, 4]; + let v = [1, 2, 3, 4]; for (idx, val) in l.iter().enumerate() { assert_eq!(v[idx], *val); } diff --git a/src/trie.rs b/src/trie.rs index 9e607b6..39fc978 100644 --- a/src/trie.rs +++ b/src/trie.rs @@ -66,7 +66,7 @@ impl Trie { return v.get_store(tail); } } - return Option::None; + Option::None } } @@ -94,7 +94,7 @@ impl Trie { return Option::Some(new_trie); } } - return Option::None; + Option::None } } @@ -138,7 +138,7 @@ mod tests { #[test] fn test_trie_persistance() { - let vs = vec!["aab", "adc", "acd", "dca"]; + let vs = ["aab", "adc", "acd", "dca"]; let snapshots: Vec<_> = vs .iter() .scan(Trie::empty(), |tree, value| { @@ -150,7 +150,7 @@ mod tests { let found = vs .iter() .map(|s| tree.search(s)) - .filter(|found| *found == true) + .filter(|found| *found) .count(); assert_eq!(found, index + 1); } @@ -178,7 +178,7 @@ mod tests { fn test_trie_deletion() { let t = Trie::empty().insert("aab").delete("aab"); assert!(t.is_some()); - assert_eq!(t.unwrap().search("aab"), false); + assert!(!t.unwrap().search("aab")); let t2 = Trie::empty(); assert!(t2.delete("a").is_none()); } @@ -241,12 +241,12 @@ mod tests { trie = trie.insert("grape").insert("banana-split"); // Check for words in current trie - assert_eq!(trie.search("grape"), true); + assert!(trie.search("grape")); // Restore trie to a previous of moment in time trie = snapshot; // Word was not present at snapshop moment - assert_eq!(trie.search("grape"), false); + assert!(!trie.search("grape")); } }