Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add clippy to ci #3

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 7 additions & 10 deletions src/avl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,10 @@ impl<K: Ord> AVL<K> {

impl<K: Ord, V> AVL<K, V> {
pub fn empty() -> AVL<K, V> {
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 {
Expand All @@ -72,7 +69,7 @@ impl<K: Ord, V> AVL<K, V> {
value: _,
left,
right,
} => &left.height() - &right.height(),
} => left.height() - right.height(),
}
}
pub fn find(&self, target_value: &K) -> Option<&V> {
Expand Down Expand Up @@ -118,7 +115,7 @@ impl<K: Ord, V> AVL<K, V> {
};
}
}
return self.clone();
self.clone()
}
fn right_fix(&self) -> AVL<K, V> {
if let AVL::Node {
Expand All @@ -140,7 +137,7 @@ impl<K: Ord, V> AVL<K, V> {
return self.right_rotation();
}
}
return self.clone();
self.clone()
}
fn left_rotation(&self) -> AVL<K, V> {
if let AVL::Node {
Expand Down Expand Up @@ -170,7 +167,7 @@ impl<K: Ord, V> AVL<K, V> {
};
}
}
return self.clone();
self.clone()
}
fn left_fix(&self) -> AVL<K, V> {
if let AVL::Node {
Expand All @@ -192,7 +189,7 @@ impl<K: Ord, V> AVL<K, V> {
return self.left_rotation();
}
}
return self.clone();
self.clone()
}
fn fix(&self) -> AVL<K, V> {
match self.diff() {
Expand Down
6 changes: 3 additions & 3 deletions src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ impl<T> List<T> {
}
}
pub fn empty() -> List<T> {
return List {
List {
head: RefCounter::new(ListNode::Empty),
len: 0,
};
}
}
fn push_front_rc(&self, rc_value: RefCounter<T>) -> List<T> {
List {
Expand Down Expand Up @@ -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);
}
Expand Down
14 changes: 7 additions & 7 deletions src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl<T: PartialEq + Clone, U> Trie<T, U> {
return v.get_store(tail);
}
}
return Option::None;
Option::None
}
}

Expand Down Expand Up @@ -94,7 +94,7 @@ impl<T: PartialEq + Clone, U: PartialEq> Trie<T, U> {
return Option::Some(new_trie);
}
}
return Option::None;
Option::None
}
}

Expand Down Expand Up @@ -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| {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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"));
}
}