How to convert &std::vec::Vec<(&u32, &u32)> to &std::vec::Vec<(u32, u32)>?

I have sorted hashmap an I need convert to Vec<(u32,u32)>.

let mut sorted_vec: Vec<_> = hash_map.iter().collect();
sorted_vec.sort_by(|a, b| a.partial_cmp(b).unwrap()); 

How to convert &std::vec::Vec<(&u32, &u32)> to &std::vec::Vec<(u32, u32)> ?

You can do this:

let mut vec: Vec<_> = hash_map.iter().map(|(a, b)| (*a, *b)).collect();
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.