Last active
March 18, 2020 18:17
-
-
Save NebulaFox/bb5cf515622246c050d1b6a52e029254 to your computer and use it in GitHub Desktop.
HashSet contains problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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