How to check if HashSet contains specific value in Rust

1 Answer

0 votes
use std::collections::HashSet;
  
fn main() {
    let mut hs = HashSet::new();
  
    hs.insert("Rust");
    hs.insert("C");
    hs.insert("C");
    hs.insert("C++");
    hs.insert("Java");
  
    if hs.contains(&"Rust") {
        println!("found");
    } else {
        println!("not found");
    }
}




/*
run:

found

*/

 



answered Oct 30, 2022 by avibootz
...