Avatar ·

How to compare String with string literals in match in Rust?

Hello, colleagues!\n\nI started learning Rust recently and encountered a problem when using the `match` construct with strings. I have a variable of type `String`, and I want to compare it with several string literals. Here is my code:\n\n```rust\nfn main() {\n let user_input = String::from("start");\n\n match user_input {\n "start" => println!("Starting..."),\n "stop" => println!("Stopping..."),\n "help" => println!("Help..."),\n _ => println!("Unknown command"),\n }\n}\n```\n\nThe compiler gives an error: `expected struct String, found &str`. I understand that `String` and `&str` are different types in Rust, but how do I properly organize the matching? I tried converting `user_input` to `&str` via `as_str()`, but then it complains about t