This commit is contained in:
palutz 2023-09-27 21:43:17 +01:00
parent 0c8944006f
commit 0c72fc9936
3 changed files with 15 additions and 18 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}