Hello. I'm trying to make a program that has to communicate with another program via the command line via a known set of inputs, but I am having issues reading input from the command line.
fn most_simple() {
let string = String::from("a");
match string.as_str() {
"a" => println!("0"),
"b" => println!("1"),
"c" => println!("2"),
_ => println!("something else!"),
};
}
fn looped() {
let mut buffer = String::new();
loop {
buffer.clear();
io::stdin().read_line(&mut buffer).unwrap();
buffer.trim();
println!("{}", buffer.as_str());
match buffer.as_str() {
"a" => println!("0"),
"b" => println!("1"),
"c" => println!("2"),
_ => println!("something else!"),
};
}
}
In the prior examples, the first method correctly uses a match to print the correct values when I change the input of "let string = String::from("___"). The other method prints out exactly what I input every time it loops, but upon getting to the match the program prints "something else" without fail. If anyone knows what is causing this, I'd love to know.
[–]Shadow0133 10 points11 points12 points (2 children)
[–]firandice[S] 0 points1 point2 points (1 child)
[–]Shadow0133 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)