mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-23 14:12:23 -05:00
strings2 solution
This commit is contained in:
parent
bd63ece47c
commit
f574905b8e
3 changed files with 22 additions and 8 deletions
|
@ -1,14 +1,14 @@
|
|||
// Make me compile without changing the function signature!
|
||||
// TODO: Fix the compiler error in the `main` function without changing this function.
|
||||
fn is_a_color_word(attempt: &str) -> bool {
|
||||
attempt == "green" || attempt == "blue" || attempt == "red"
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let word = String::from("green"); // Try not changing this line :)
|
||||
let word = String::from("green"); // Don't change this line.
|
||||
|
||||
if is_a_color_word(word) {
|
||||
println!("That is a color word I know!");
|
||||
} else {
|
||||
println!("That is not a color word I know.");
|
||||
}
|
||||
}
|
||||
|
||||
fn is_a_color_word(attempt: &str) -> bool {
|
||||
attempt == "green" || attempt == "blue" || attempt == "red"
|
||||
}
|
||||
|
|
|
@ -486,7 +486,7 @@ dir = "09_strings"
|
|||
test = false
|
||||
hint = """
|
||||
Yes, it would be really easy to fix this by just changing the value bound to
|
||||
`word` to be a string slice instead of a `String`, wouldn't it?? There is a way
|
||||
`word` to be a string slice instead of a `String`, wouldn't it? There is a way
|
||||
to add one character to the `if` statement, though, that will coerce the
|
||||
`String` into a string slice.
|
||||
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue