How to turn a (T, usize) collection into a HashBag?
myarcana opened this issue · comments
My Arcana commented
let mut bag = HashBag::new();
bag.insert("a");
bag.insert("b");
bag.insert("b");
let bag_as_vec = bag.set_iter().collect::<Vec<(&&str, usize)>>();
Is there a way to turn bag_as_vec
back into a HashBag
?
And how about for collections or iterators in general with types like Vec<T, usize>
(that didn't come from HashBag::SetIter) ?
Jon Gjengset commented
HashBag
implements Extend<(T, usize)>
, so you should be able to just:
let mut bag = HashBag::new();
bag.extend(bag_as_vec);