Skip to content

Commit a26a5ca

Browse files
author
build
committed
feat:exercises
1 parent 865b9a2 commit a26a5ca

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

exercises/clippy/clippy3.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
11
// clippy3.rs
2-
//
2+
//
33
// Here's a couple more easy Clippy fixes, so you can see its utility.
44
//
55
// Execute `rustlings hint clippy3` or use the `hint` watch subcommand for a hint.
66

7-
// I AM NOT DONE
8-
97
#[allow(unused_variables, unused_assignments)]
108
fn main() {
119
let my_option: Option<()> = None;
12-
if my_option.is_none() {
13-
my_option.unwrap();
10+
if let Some(x) = my_option {
11+
println!("This won't print: {x:?}");
1412
}
1513

16-
let my_arr = &[
17-
-1, -2, -3
18-
-4, -5, -6
19-
];
20-
println!("My array! Here it is: {:?}", my_arr);
14+
let my_arr = &[-1, -2, -3, -4, -5, -6];
15+
println!("My array! Here it is: {my_arr:?}");
2116

22-
let my_empty_vec = vec![1, 2, 3, 4, 5].resize(0, 5);
23-
println!("This Vec is empty, see? {:?}", my_empty_vec);
17+
let mut my_empty_vec = vec![1, 2, 3, 4, 5];
18+
my_empty_vec.clear();
19+
println!("This Vec is empty, see? {my_empty_vec:?}");
2420

2521
let mut value_a = 45;
2622
let mut value_b = 66;
2723
// Let's swap these two!
28-
value_a = value_b;
29-
value_b = value_a;
30-
println!("value a: {}; value b: {}", value_a, value_b);
24+
std::mem::swap(&mut value_a, &mut value_b);
25+
println!("value a: {value_a}; value b: {value_b}");
3126
}

0 commit comments

Comments
 (0)