Suppose I have two hash maps:
let mut a : HashMap<u64, u32> = HashMap::new();
let mut b : HashMap<u64, u32> = HashMap::new();
How can I add the a
hash map to the b
? If they were vectors Vec
, I would simply call Vec::append()
.
Suppose I have two hash maps:
let mut a : HashMap<u64, u32> = HashMap::new();
let mut b : HashMap<u64, u32> = HashMap::new();
How can I add the a
hash map to the b
? If they were vectors Vec
, I would simply call Vec::append()
.
To get the union of a
and b
, try this:
a.into_iter().map(|(k, v)| b.insert(k, v));
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.