Skip to content

Instantly share code, notes, and snippets.

@NebulaFox
Last active March 16, 2020 15:52
Show Gist options
  • Save NebulaFox/6f681ef9a1765b498dd22e2c0c5fb5d1 to your computer and use it in GitHub Desktop.
Save NebulaFox/6f681ef9a1765b498dd22e2c0c5fb5d1 to your computer and use it in GitHub Desktop.
HashSet<&String> to be coerced into HashSet<&str>
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