Mapping HashMap value HashSet to BTreeMap value BTreeSet

I would like to write a function to convert from unordered to ordered collections with the types as follows:

fn hash_to_btree(hash: HashMap<i32, HashSet<i32>>) -> BTreeMap<i32, BTreeSet<i32>> {
  // ?
}

What is an idiomatic way to code this function?

fn hash_to_btree(hash: HashMap<i32, HashSet<i32>>) -> BTreeMap<i32, BTreeSet<i32>> {
    hash.into_iter().map(|(k, v)| (k, v.into_iter().collect())).collect()
}

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.