pWorking on the same example beginner code as in my last post in help, I decided to create a function which reads yes/no from the console and outputs true/false:
fn bool_from_yesno() -> bool {
let mut yes_no = String::new();
io::stdin().read_line(&mut yes_no).expect("error reading the line!");
match yes_no.as_str() {
"yes" => true,
"no" => false,
_ => false,
}
}
Now at first it looks okay to me, however it only outputs false. In so far I most likely made an beginner error.
read_line will include the newline character in the data that it reads, but your match arms don't include one (so you're always getting the _ case). You'll probably want to match on yes_no.trim() instead.
One wish for a tutorial book is being that this is elaborated on as on google the as_str() function pops up first when inputting "String to string literal".