mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-12 05:39:19 +00:00
feat: 🎸 added solutions for clippy exercises
This commit is contained in:
parent
9e6f99d90f
commit
85ba2e3c7b
@ -6,15 +6,13 @@
|
|||||||
// check clippy's suggestions from the output to solve the exercise.
|
// check clippy's suggestions from the output to solve the exercise.
|
||||||
// Execute `rustlings hint clippy1` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint clippy1` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
use std::f32;
|
use std::f32;
|
||||||
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let pi = 3.14f32;
|
|
||||||
let radius = 5.00f32;
|
let radius = 5.00f32;
|
||||||
|
|
||||||
let area = pi * f32::powi(radius, 2);
|
let area = PI * f32::powi(radius, 2);
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"The area of a circle with radius {:.2} is {:.5}!",
|
"The area of a circle with radius {:.2} is {:.5}!",
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
// clippy2.rs
|
// clippy2.rs
|
||||||
// Execute `rustlings hint clippy2` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint clippy2` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut res = 42;
|
let mut res = 42;
|
||||||
let option = Some(12);
|
let option = Some(12);
|
||||||
for x in option {
|
if let Some(x) = option {
|
||||||
res += x;
|
res += x;
|
||||||
}
|
}
|
||||||
println!("{}", res);
|
println!("{}", res);
|
||||||
|
|||||||
@ -1,28 +1,25 @@
|
|||||||
// clippy3.rs
|
// clippy3.rs
|
||||||
// Here's a couple more easy Clippy fixes, so you can see its utility.
|
// Here's a couple more easy Clippy fixes, so you can see its utility.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
#[allow(unused_variables, unused_assignments)]
|
#[allow(unused_variables, unused_assignments)]
|
||||||
fn main() {
|
fn main() {
|
||||||
let my_option: Option<()> = None;
|
let my_option: Option<()> = None;
|
||||||
if my_option.is_none() {
|
if let Some(x) = my_option {
|
||||||
my_option.unwrap();
|
my_option.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let my_arr = &[
|
let my_arr = &[-1, -2, -3, -4, -5, -6];
|
||||||
-1, -2, -3
|
|
||||||
-4, -5, -6
|
|
||||||
];
|
|
||||||
println!("My array! Here it is: {:?}", my_arr);
|
println!("My array! Here it is: {:?}", my_arr);
|
||||||
|
|
||||||
let my_empty_vec = vec![1, 2, 3, 4, 5].resize(0, 5);
|
println!(
|
||||||
println!("This Vec is empty, see? {:?}", my_empty_vec);
|
"This Vec is empty, see? {:?}",
|
||||||
|
vec![1, 2, 3, 4, 5].resize(0, 5)
|
||||||
|
);
|
||||||
|
|
||||||
let mut value_a = 45;
|
let mut value_a = 45;
|
||||||
let mut value_b = 66;
|
let mut value_b = 66;
|
||||||
|
|
||||||
// Let's swap these two!
|
// Let's swap these two!
|
||||||
value_a = value_b;
|
std::mem::swap(&mut value_a, &mut value_b);
|
||||||
value_b = value_a;
|
|
||||||
println!("value a: {}; value b: {}", value_a, value_b);
|
println!("value a: {}; value b: {}", value_a, value_b);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user