Skip to content

Commit e711dbb

Browse files
committed
FEAT: Add .sort_keys()
1 parent 3a77c7f commit e711dbb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,18 @@ impl<K, V, S> OrderMap<K, V, S>
11101110
});
11111111
}
11121112

1113+
/// Sort the map’s key-value pairs by the default ordering of the keys.
1114+
pub fn sort_keys(&mut self)
1115+
where K: Ord,
1116+
{
1117+
self.sort_by(|k1, _, k2, _| Ord::cmp(k1, k2))
1118+
}
1119+
1120+
/// Sort the map’s key-value pairs in place using the comparison
1121+
/// function `compare`.
1122+
///
1123+
/// The comparison function receives two key and value pairs to compare (you
1124+
/// can sort by keys or values or their combination as needed).
11131125
pub fn sort_by<F>(&mut self, mut compare: F)
11141126
where F: FnMut(&K, &V, &K, &V) -> Ordering,
11151127
{

0 commit comments

Comments
 (0)