Last active
March 16, 2020 15:52
-
-
Save NebulaFox/6f681ef9a1765b498dd22e2c0c5fb5d1 to your computer and use it in GitHub Desktop.
HashSet<&String> to be coerced into HashSet<&str>
This file contains 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() { | |
// move strings into HashSet | |
let known_values: HashSet<&str> = ["a", "b", "c"] | |
.iter().cloned().collect(); | |
// provided an Vec<String> | |
let provided_values: Vec<String> = vec![ | |
"a".to_string(), | |
"b".to_string(), | |
"z".to_string() | |
]; | |
// hash set of refrences | |
let mut found: HashSet<&String> = HashSet::new(); | |
found.insert(&provided_values[0]); | |
found.insert(&provided_values[1]); | |
found.insert(&provided_values[2]); | |
//let missing = known_values.difference(&found); | |
let missing = found.difference(&known_values); | |
println!("missing: {:#?}", missing); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment