If I have:
my_hash_map: HashMap<usize, MyStruct>,
and I do:
I get a
HashMapIter<'_, usize, MyStruct> that iterates in arbitrary order.
Is there a way to iterate in the order of the keys? They are ordered because the key is a
Change your type to
BTreeMap<usize, MyStruct> which stores the keys in order. HashMap doesn't store keys in order.
Another option is to collect the keys into a vector and sort it.
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.