Skip to content

Instantly share code, notes, and snippets.

@NebulaFox
Last active March 18, 2020 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NebulaFox/bb5cf515622246c050d1b6a52e029254 to your computer and use it in GitHub Desktop.
Save NebulaFox/bb5cf515622246c050d1b6a52e029254 to your computer and use it in GitHub Desktop.
HashSet contains problem
use std::collections::HashSet;
fn main() {
let hs_str: HashSet<&str> = ["a", "b", "c"].iter().copied().collect();
let hs_string: HashSet<String> = vec!["a".to_string(), "b".to_string(), "c".to_string()]
.into_iter()
.collect();
let value_str = "b";
let value_string = String::from(value_str);
let result_str = hs_str.contains(&value_string);
let result_string = hs_string.contains(&value_str);
let result_literal = hs_string.contains("a");
println!(
"result: {} {} {}",
result_str, result_string, result_literal
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment