0

I'm trying to get a boolean string from the user and match it with multiple options so as to support multiple boolean inputs, but the control always goes to the default case and is not matching the correct case.

let mut input_str = String::new();
io::stdin()
    .read_line(&mut input_str)
    .expect("read failed");

match input_str.as_str() {
    "true" => println!("true"),
    "t" => println!("t"),
    "false" => println!("false"),
    "f" => println!("f"),
    _ => println!("default")
}

But if use a hardcoded &str like let input_str = "true";, it gets matched to the correct case.

cafce25
  • 15,907
  • 4
  • 25
  • 31

0 Answers0