diff --git a/exercises/clippy/clippy1.rs b/exercises/clippy/clippy1.rs index 95c0141f..6a4c3339 100644 --- a/exercises/clippy/clippy1.rs +++ b/exercises/clippy/clippy1.rs @@ -9,12 +9,10 @@ // Execute `rustlings hint clippy1` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE - -use std::f32; +use std::f32::{self, consts::PI}; fn main() { - let pi = 3.14f32; + let pi = PI; // changed to the consts value let radius = 5.00f32; let area = pi * f32::powi(radius, 2); diff --git a/exercises/clippy/clippy2.rs b/exercises/clippy/clippy2.rs index 9b87a0b7..b8f7aec7 100644 --- a/exercises/clippy/clippy2.rs +++ b/exercises/clippy/clippy2.rs @@ -3,13 +3,12 @@ // Execute `rustlings hint clippy2` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE - fn main() { let mut res = 42; let option = Some(12); - for x in option { - res += x; + // switching to if let ... + if let Some(n) = option { + res += n; } println!("{}", res); } diff --git a/exercises/clippy/clippy3.rs b/exercises/clippy/clippy3.rs index 35021f84..9caab13f 100644 --- a/exercises/clippy/clippy3.rs +++ b/exercises/clippy/clippy3.rs @@ -4,28 +4,28 @@ // // Execute `rustlings hint clippy3` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE - #[allow(unused_variables, unused_assignments)] fn main() { let my_option: Option<()> = None; - if my_option.is_none() { - my_option.unwrap(); - } + // if my_option.is_none() { + // my_option.unwrap(); + // } let my_arr = &[ - -1, -2, -3 - -4, -5, -6 + -1, -2, -3, + -4, -5, -6, ]; println!("My array! Here it is: {:?}", my_arr); - let my_empty_vec = vec![1, 2, 3, 4, 5].resize(0, 5); + let mut my_empty_vec = vec![1, 2, 3, 4, 5]; + my_empty_vec.clear(); println!("This Vec is empty, see? {:?}", my_empty_vec); let mut value_a = 45; let mut value_b = 66; // Let's swap these two! - value_a = value_b; - value_b = value_a; + // value_a = value_b; + // value_b = value_a; + value_a = std::mem::replace(&mut value_b, value_a); println!("value a: {}; value b: {}", value_a, value_b); }