rustlings

solving rustlings ft. dracuxan
git clone [email protected]:dracuxan/rustlings.git
Log | Files | Refs

strings2.rs (451B)


      1 fn is_a_color_word(attempt: &str) -> bool {
      2     attempt == "green" || attempt == "blue" || attempt == "red"
      3 }
      4 
      5 fn main() {
      6     let word = String::from("green");
      7 
      8     if is_a_color_word(&word) {
      9         //             ^ added to have `&String` which is automatically
     10         //               coerced to `&str` by the compiler.
     11         println!("That is a color word I know!");
     12     } else {
     13         println!("That is not a color word I know.");
     14     }
     15 }