I'm trying to adapt my code to a solution to my previous question. Basically, I have a HashMap<String, HashSet<String>>
that should be generated as a result of rayon's par_extend. The problem is that keys repeat and in such a case, I want HashSet
s to be combined, as opposed to overwritten. In other words, is there a way to add a custom impl Extend
here so that the following code executes properly?
use std::collections::{HashMap, HashSet};
fn main() {
let mut d: HashMap<String, HashSet<String>> = HashMap::new();
d.extend(vec![1, 2].iter().map(|x| {
let mut z = HashSet::new();
z.insert(x.to_string());
return ("a".into(), z);
}));
assert_eq!(d.get("a").unwrap().len(), 2);
}