Skip to content

Commit b1b71d6

Browse files
committed
FEAT: Add .sort_keys()
1 parent 3df49ba commit b1b71d6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/lib.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,18 @@ impl<K, V, S> OrderMap<K, V, S>
10441044
}
10451045
}
10461046

1047+
/// Sort the map’s key-value pairs by the default ordering of the keys.
1048+
pub fn sort_keys(&mut self)
1049+
where K: Ord,
1050+
{
1051+
self.sort_by(|k1, _, k2, _| Ord::cmp(k1, k2))
1052+
}
1053+
1054+
/// Sort the map’s key-value pairs in place using the comparison
1055+
/// function `compare`.
1056+
///
1057+
/// The comparison function receives two key and value pairs to compare (you
1058+
/// can sort by keys or values or their combination as needed).
10471059
pub fn sort_by<F>(&mut self, mut compare: F)
10481060
where F: FnMut(&K, &V, &K, &V) -> Ordering,
10491061
{

0 commit comments

Comments
 (0)