+ 3

Rust string error

// first question println!("what CPU stand for?"); let mut first_answer: String = String::new(); io::stdin() .read_line(&mut first_answer) .expect("Something went wrong"); let first_answer = first_answer.trim_end(); // Check if the answer from first question correct or not match first_answer.to_lowercase() { "central processing unit" => { println!("Congratulations you're Correct. Good job 👍"); println!("next question.."); }, _ => println!("Unfortunately you're incorrect"), }; Error message: expected struct `String`, found `&str`

11th Feb 2022, 12:43 AM
EsaKurniawan
5 Answers
+ 1
match first_answer.to_lowercase().as_str() { ... }
13th Feb 2022, 12:55 PM
Ashish Anand
Ashish Anand - avatar
+ 1
"central processing unit" is of type &str but first_answer.to_lowercase() returns String and you are trying to compare both
13th Feb 2022, 3:52 PM
Ashish Anand
Ashish Anand - avatar
0
Actually already solved it with if else startment in rust
13th Feb 2022, 2:28 PM
EsaKurniawan
0
One more question
13th Feb 2022, 2:28 PM
EsaKurniawan
0
Why when i use if else startment doesn't get any error and when i use match i am getting an error
13th Feb 2022, 2:29 PM
EsaKurniawan