Converting from HashSet<String>
to Vec<String>
is pretty straightforward:
let hs: HashSet<String> = HashSet::new();
let v: Vec<String> = hs.into_iter().collect();
What's the easiest way to do the same but from a reference to a HashSet?
This doesn't work:
let hs: HashSet<String> = HashSet::new();
let ref_to_hs: &HashSet<String> = &hs;
let v: Vec<String> = ref_to_hs.into_iter().collect();
It results in:
error[E0277]: a value of type `Vec<std::string::String>` cannot be built from an iterator over elements of type `&std::string::String`