diff options
Diffstat (limited to 'rustlings/solutions/09_strings/strings2.rs')
| -rw-r--r-- | rustlings/solutions/09_strings/strings2.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/rustlings/solutions/09_strings/strings2.rs b/rustlings/solutions/09_strings/strings2.rs index dcf2377..7de311f 100644 --- a/rustlings/solutions/09_strings/strings2.rs +++ b/rustlings/solutions/09_strings/strings2.rs @@ -1,4 +1,15 @@ +fn is_a_color_word(attempt: &str) -> bool { + attempt == "green" || attempt == "blue" || attempt == "red" +} + fn main() { - // DON'T EDIT THIS SOLUTION FILE! - // It will be automatically filled after you finish the exercise. + let word = String::from("green"); + + if is_a_color_word(&word) { + // ^ added to have `&String` which is automatically + // coerced to `&str` by the compiler. + println!("That is a color word I know!"); + } else { + println!("That is not a color word I know."); + } } |