Skip to content

Commit be173dc

Browse files
committed
Apply clippy fixes.
1 parent d579df7 commit be173dc

File tree

8 files changed

+17
-23
lines changed

8 files changed

+17
-23
lines changed

src/bin/c01p02.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ fn is_permutation(s1: &str, s2: &str) -> bool {
1313
let characters_2 = count_chars(s2);
1414

1515
for key in characters_1.keys() {
16-
if !characters_2.contains_key(&key) {
16+
if !characters_2.contains_key(key) {
1717
return false;
1818
}
19-
if characters_1.get(&key) != characters_2.get(&key) {
19+
if characters_1.get(key) != characters_2.get(key) {
2020
return false;
2121
}
2222
}
2323
for key in characters_2.keys() {
24-
if !characters_1.contains_key(&key) {
24+
if !characters_1.contains_key(key) {
2525
return false;
2626
}
2727
}

src/bin/c01p03.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn urlify(url: &'static str) -> String {
1212

1313
// Alternative solution with shorter syntax
1414
fn urlify_2(url: &str) -> String {
15-
url.trim().replace(" ", "%20")
15+
url.trim().replace(' ', "%20")
1616
}
1717

1818
#[cfg(test)]
@@ -21,15 +21,15 @@ mod tests {
2121

2222
#[test]
2323
fn test_urlify() {
24-
assert_eq!(urlify(&"Mr John Smith "), "Mr%20John%20Smith");
24+
assert_eq!(urlify("Mr John Smith "), "Mr%20John%20Smith");
2525
}
2626
#[test]
2727
fn test_urlify_2() {
28-
assert_eq!(urlify_2(&"Mr John Smith "), "Mr%20John%20Smith");
28+
assert_eq!(urlify_2("Mr John Smith "), "Mr%20John%20Smith");
2929
}
3030
}
3131

3232
fn main() {
33-
urlify(&"Mr John Smith ");
34-
urlify_2(&"Mr John Smith ");
33+
urlify("Mr John Smith ");
34+
urlify_2("Mr John Smith ");
3535
}

src/bin/c05p07.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
fn bitwise_swap(a: &mut i32, b: &mut i32) {
2-
*a ^= *b;
3-
*b ^= *a;
4-
*a ^= *b;
2+
std::mem::swap(&mut (*a), &mut (*b))
53
}
64

75
#[cfg(test)]

src/bin/c07p03.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ impl Jukebox {
4646
if self.queue.is_empty() {
4747
// pick random song
4848
let mut rng = thread_rng();
49-
if let Some(song) = self.catalogue.choose(&mut rng) {
50-
Some(song.clone())
51-
} else {
52-
None
53-
}
49+
self.catalogue.choose(&mut rng).cloned()
5450
} else {
5551
Some(self.queue.remove(0))
5652
}

src/bin/c08p02.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(clippy::same_item_push, clippy::unknown_clippy_lints)]
1+
#![allow(clippy::same_item_push, unknown_lints)]
22

33
#[derive(Clone, Copy, Debug, PartialEq)]
44
struct Location {

src/bin/c08p07.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ mod tests {
4141
fn test_permutations_without_dups() {
4242
let s1 = "abc";
4343
let permutations = vec!["abc", "bac", "bca", "acb", "cab", "cba"];
44-
assert_eq!(permutations_without_dups(&s1), permutations);
44+
assert_eq!(permutations_without_dups(s1), permutations);
4545

4646
let s2 = "abcdefg";
47-
let s2_perms = permutations_without_dups(&s2);
47+
let s2_perms = permutations_without_dups(s2);
4848
let s2_set = hashset(&s2_perms);
4949
assert_eq!(s2_perms.len(), 5040);
5050
assert_eq!(s2_perms.len(), s2_set.len());
@@ -53,5 +53,5 @@ mod tests {
5353

5454
fn main() {
5555
let s1 = "abc";
56-
permutations_without_dups(&s1);
56+
permutations_without_dups(s1);
5757
}

src/bin/c08p08.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ mod tests {
3434
fn test_permutations_with_dups() {
3535
let s1 = "abb";
3636
let permutations = vec!["abb", "bab", "bba", "abb", "bab", "bba"];
37-
assert_eq!(permutations_with_dups(&s1), permutations);
37+
assert_eq!(permutations_with_dups(s1), permutations);
3838
}
3939
}
4040

4141
fn main() {
4242
let s1 = "abc";
43-
permutations_with_dups(&s1);
43+
permutations_with_dups(s1);
4444
}

src/bin/c08p12.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn check_valid(columns: &mut Vec<usize>, row1: usize, column1: usize) -> bool {
66
return false;
77
}
88

9-
let column_distance = ((*column2 as i64) - (column1 as i64)).abs() as usize;
9+
let column_distance = ((*column2 as i64) - (column1 as i64)).unsigned_abs() as usize;
1010

1111
let row_distance = row1 - row2;
1212
if column_distance == row_distance {

0 commit comments

Comments
 (0)