How do I check if a thing is in a vector

There is the contains (https://doc.rust-lang.org/std/vec/struct.Vec.html#method.contains) method on Vec.

Example:

let n = vec!["-i","mmmm"];

if n.contains(&"-i") { 
    println!("yes");
} else {
    println!("no");
}

It is somewhat restrictive, for instance it doesn’t allow checking if a Vec<String> contains x if x is of type &str. In that case, you will have to use the .iter().any(...) method described by @harmic

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)