Skip to content

Commit c3a7ae7

Browse files
committed
Fix a bunch of clippy errors.
1 parent c10d1a1 commit c3a7ae7

File tree

14 files changed

+38
-34
lines changed

14 files changed

+38
-34
lines changed

src/bin/c02p01.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ where
6969
fn tail(&self) -> Option<NodeRef<T>> {
7070
if let Some(cur) = self.head.as_ref().cloned() {
7171
if cur.borrow().next.is_none() {
72-
return Some(cur.clone());
72+
return Some(cur);
7373
} else {
74-
return Node::tail(&cur.clone());
74+
return Node::tail(&cur);
7575
}
7676
}
7777
None
@@ -121,7 +121,7 @@ impl<'a, T> Iterator for Iter<T> {
121121
fn next(&mut self) -> Option<Self::Item> {
122122
if let Some(cur) = self.next.as_ref().cloned() {
123123
self.next = cur.borrow().next.clone();
124-
return Some(cur.clone());
124+
return Some(cur);
125125
}
126126
None
127127
}

src/bin/c02p02.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,16 @@ where
6666
}
6767

6868
fn kth_to_last(&self, k: usize) -> Option<NodeRef<T>> {
69+
use std::cmp::Ordering;
70+
6971
let mut kth_to_last_node: Option<NodeRef<T>> = None;
7072
for (c, _) in self.iter().enumerate() {
71-
if c == k {
72-
kth_to_last_node = self.head.as_ref().cloned();
73-
} else if c > k {
74-
kth_to_last_node = kth_to_last_node.unwrap().borrow().next.as_ref().cloned();
73+
match k.cmp(&c) {
74+
Ordering::Equal => kth_to_last_node = self.head.as_ref().cloned(),
75+
Ordering::Less => {
76+
kth_to_last_node = kth_to_last_node.unwrap().borrow().next.as_ref().cloned()
77+
}
78+
_ => (),
7579
}
7680
}
7781
kth_to_last_node

src/bin/c02p04.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct Iter<T> {
2020
impl<T> Node<T> {
2121
fn tail(node: &NodeRef<T>) -> Option<NodeRef<T>> {
2222
if let Some(cur) = node.borrow().next.as_ref().cloned() {
23-
return Node::tail(&cur.clone());
23+
return Node::tail(&cur);
2424
}
2525
Some(node.clone())
2626
}
@@ -67,9 +67,9 @@ where
6767
fn tail(&self) -> Option<NodeRef<T>> {
6868
if let Some(cur) = self.head.as_ref().cloned() {
6969
if cur.borrow().next.is_none() {
70-
return Some(cur.clone());
70+
return Some(cur);
7171
} else {
72-
return Node::tail(&cur.clone());
72+
return Node::tail(&cur);
7373
}
7474
}
7575
None
@@ -88,7 +88,7 @@ impl<'a, T> Iterator for Iter<T> {
8888
fn next(&mut self) -> Option<Self::Item> {
8989
if let Some(cur) = self.next.as_ref().cloned() {
9090
self.next = cur.borrow().next.clone();
91-
return Some(cur.clone());
91+
return Some(cur);
9292
}
9393
None
9494
}

src/bin/c02p05.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ where
5151
fn tail(&self) -> Option<NodeRef<T>> {
5252
if let Some(cur) = self.head.as_ref().cloned() {
5353
if cur.borrow().next.is_none() {
54-
return Some(cur.clone());
54+
return Some(cur);
5555
} else {
5656
return Node::tail(&cur.clone());
5757
}
@@ -72,7 +72,7 @@ impl<'a, T> Iterator for Iter<T> {
7272
fn next(&mut self) -> Option<Self::Item> {
7373
if let Some(cur) = self.next.as_ref().cloned() {
7474
self.next = cur.borrow().next.clone();
75-
return Some(cur.clone());
75+
return Some(cur);
7676
}
7777
None
7878
}

src/bin/c02p06.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<'a, T> Iterator for Iter<T> {
8181
if Rc::ptr_eq(&cur, self.prev.as_ref().unwrap()) {
8282
return None;
8383
}
84-
return Some(cur.clone());
84+
return Some(cur);
8585
}
8686
None
8787
}
@@ -94,7 +94,7 @@ impl<'a, T> DoubleEndedIterator for Iter<T> {
9494
if Rc::ptr_eq(self.next.as_ref().unwrap(), &cur) {
9595
return None;
9696
}
97-
return Some(cur.clone());
97+
return Some(cur);
9898
}
9999
None
100100
}

src/bin/c02p08.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ where
5555
fn tail(&self) -> Option<NodeRef<T>> {
5656
if let Some(cur) = self.head.as_ref().cloned() {
5757
if cur.borrow().next.is_none() {
58-
return Some(cur.clone());
58+
return Some(cur);
5959
} else {
6060
return Node::tail(&cur.clone());
6161
}
@@ -80,7 +80,7 @@ where
8080
while hare.is_some() && tortoise.is_some() {
8181
if Rc::ptr_eq(hare.as_ref().unwrap(), tortoise.as_ref().unwrap()) {
8282
if Rc::ptr_eq(&prev_tortoise, &prev_hare) {
83-
return Some(prev_tortoise.clone());
83+
return Some(prev_tortoise);
8484
} else {
8585
return Some(hare.as_ref().unwrap().clone());
8686
}
@@ -104,7 +104,7 @@ impl<'a, T> Iterator for Iter<T> {
104104
self.next.as_ref()?;
105105
if let Some(cur) = self.next.as_ref().cloned() {
106106
self.next = cur.borrow().next.clone();
107-
return Some(cur.clone());
107+
return Some(cur);
108108
}
109109
None
110110
}
@@ -142,7 +142,7 @@ mod tests {
142142
list_iter.next();
143143
list_iter.next();
144144
let third_node = list_iter.next();
145-
cycle_list.tail().unwrap().borrow_mut().next = Some(third_node.unwrap().clone());
145+
cycle_list.tail().unwrap().borrow_mut().next = Some(third_node.unwrap());
146146

147147
let cycle_result = cycle_list.has_cycle();
148148
assert_eq!(cycle_result.is_some(), true);
@@ -168,7 +168,7 @@ mod tests {
168168
list_iter2.next();
169169
list_iter2.next();
170170
let third_node2 = list_iter2.next();
171-
cycle_list2.tail().unwrap().borrow_mut().next = Some(third_node2.unwrap().clone());
171+
cycle_list2.tail().unwrap().borrow_mut().next = Some(third_node2.unwrap());
172172

173173
let cycle_result2 = cycle_list2.has_cycle();
174174
assert_eq!(cycle_result2.is_some(), true);

src/bin/c03p04.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ where
1414
}
1515

1616
fn add(&mut self, value: T) {
17-
self.arr.push(value.clone());
17+
self.arr.push(value);
1818
}
1919

2020
fn remove(&mut self) -> Option<T> {

src/bin/c04p01.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ mod tests {
9595
let third = graph.add_vertex(3, &[first.clone(), second.clone()]);
9696

9797
assert_eq!(graph.has_path(first.clone(), third.clone()), true);
98-
assert_eq!(graph.has_path(third.clone(), first.clone()), false);
98+
assert_eq!(graph.has_path(third, first), false);
9999
}
100100
}
101101

102102
fn main() {
103103
let mut graph = Graph::<i32>::new();
104104
let first = graph.add_vertex(1, &[]);
105105
let second = graph.add_vertex(2, &[]);
106-
graph.has_path(first.clone(), second.clone());
106+
graph.has_path(first, second);
107107
}

src/bin/c04p02.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ where
3333
ret
3434
} else {
3535
let mut head = self.head.as_mut().unwrap().clone();
36-
self.insert_at(&mut head, ret.clone())
36+
self.insert_at(&mut head, ret)
3737
}
3838
}
3939

src/bin/c04p04.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ where
3434
ret
3535
} else {
3636
let mut head = self.head.as_mut().unwrap().clone();
37-
self.insert_at(&mut head, ret.clone())
37+
self.insert_at(&mut head, ret)
3838
}
3939
}
4040

0 commit comments

Comments
 (0)