macro and clippy

This commit is contained in:
0xChasingFire 2021-06-04 11:17:24 +08:00
parent dd131cb487
commit 1c2e741495
9 changed files with 18 additions and 22 deletions

View file

@ -6,12 +6,10 @@
// check clippy's suggestions from the output to solve the exercise.
// Execute `rustlings hint clippy1` for hints :)
// I AM NOT DONE
fn main() {
let x = 1.2331f64;
let y = 1.2332f64;
if y != x {
if (y - x).abs() > 0.0001 {
println!("Success!");
}
}

View file

@ -1,12 +1,10 @@
// clippy2.rs
// Make me compile! Execute `rustlings hint clippy2` for hints :)
// I AM NOT DONE
fn main() {
let mut res = 42;
let option = Some(12);
for x in option {
if let Some(x) = option {
res += x;
}
println!("{}", res);

View file

@ -37,6 +37,7 @@ impl Default for Person {
impl From<&str> for Person {
fn from(s: &str) -> Person {
if s.len() == 0 { super::default()}
}
}

View file

@ -5,11 +5,9 @@
// The goal is to make sure that the division does not fail to compile
// and returns the proper type.
// I AM NOT DONE
fn average(values: &[f64]) -> f64 {
let total = values.iter().fold(0.0, |a, b| a + b);
total / values.len()
total / values.len() as f64
}
fn main() {

View file

@ -1,7 +1,6 @@
// macros1.rs
// Make me compile! Execute `rustlings hint macros1` for hints :)
// I AM NOT DONE
macro_rules! my_macro {
() => {
@ -10,5 +9,5 @@ macro_rules! my_macro {
}
fn main() {
my_macro();
my_macro!();
}

View file

@ -1,14 +1,14 @@
// macros2.rs
// Make me compile! Execute `rustlings hint macros2` for hints :)
// I AM NOT DONE
fn main() {
my_macro!();
}
macro_rules! my_macro {
() => {
println!("Check out my macro!");
};
}
fn main() {
my_macro!();
}

View file

@ -2,8 +2,8 @@
// Make me compile, without taking the macro out of the module!
// Execute `rustlings hint macros3` for hints :)
// I AM NOT DONE
#[macro_use]
mod macros {
macro_rules! my_macro {
() => {

View file

@ -1,12 +1,10 @@
// macros4.rs
// Make me compile! Execute `rustlings hint macros4` for hints :)
// I AM NOT DONE
macro_rules! my_macro {
() => {
println!("Check out my macro!");
}
};
($val:expr) => {
println!("Look at this other macro: {}", $val);
}

View file

@ -5,7 +5,11 @@
// Write a macro that passes the quiz! No hints this time, you can do it!
// I AM NOT DONE
macro_rules! my_macro {
($val:expr) => {
"Hello ".to_owned() + $val
};
}
#[cfg(test)]
mod tests {