From f574905b8e7d3b9320b2cb3a4c18e2039c9a771f Mon Sep 17 00:00:00 2001 From: mo8it Date: Sat, 22 Jun 2024 12:14:04 +0200 Subject: strings2 solution --- solutions/09_strings/strings2.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'solutions/09_strings/strings2.rs') 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."); + } +} -- cgit v1.2.3