Hello, I'm getting started with learning Rust and I have a question about &str
.
I have a list:
let available_toppings = ["mushroom", "pickle", "onion"];
on which I'm trying to run the contains
method. This works when I use the string literal "olive" directly like:
if available_toppings.contains(&"olive")
...
but doesn't work when I declare a variable tfor &str and then use it in contains
:
let requested_topping: &str = "olive"
if available_toppings.contains(requested_topping)
...
Can someone help me understand why the second example doesn't work ?