diff options
| author | mo8it <mo8it@proton.me> | 2024-06-22 12:14:04 +0200 |
|---|---|---|
| committer | mo8it <mo8it@proton.me> | 2024-06-22 12:14:04 +0200 |
| commit | f574905b8e7d3b9320b2cb3a4c18e2039c9a771f (patch) | |
| tree | 055dc706ee67c46a86f5c276c8b157bcf59c1fb3 /solutions/09_strings | |
| parent | bd63ece47cbb6bde9e2fe53db543a8d22a246f5e (diff) | |
strings2 solution
Diffstat (limited to 'solutions/09_strings')
| -rw-r--r-- | solutions/09_strings/strings2.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/solutions/09_strings/strings2.rs b/solutions/09_strings/strings2.rs index 4e18198..7de311f 100644 --- a/solutions/09_strings/strings2.rs +++ b/solutions/09_strings/strings2.rs @@ -1 +1,15 @@ -// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 +fn is_a_color_word(attempt: &str) -> bool { + attempt == "green" || attempt == "blue" || attempt == "red" +} + +fn main() { + 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."); + } +} |
