This snippet of code:
fn main() {
let s = "hello".to_string();
let keywords = vec!["hello", "bye"];
// if keywords.contains(&s.as_str())
if keywords.contains(&&s)
// ~> expected &&str, found &collections::string::String
{
println!("exists");
}
}
normally, when function expect &str
type, you can give a String
let s = "abc".to_string();
foo(&s); // ok,
however &&s
doesn't deref to &&str
, which I think is inconsistent.