Skip to content

Commit 766c6aa

Browse files
committed
FEAT: Add .sort_keys()
1 parent 12c4c89 commit 766c6aa

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,16 @@ impl<K, V, S> OrderMap<K, V, S>
11101110
});
11111111
}
11121112

1113+
/// Sort the map’s key-value pairs by the default order 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`; the comparison function receives two key and
1122+
/// value pairs to compare (so you can sort by keys or values).
11131123
pub fn sort_by<F>(&mut self, mut compare: F)
11141124
where F: FnMut(&K, &V, &K, &V) -> Ordering,
11151125
{

0 commit comments

Comments
 (0)