Skip to content

Commit

Permalink
FEAT: Add .sort_keys()
Browse files Browse the repository at this point in the history
  • Loading branch information
bluss committed Jan 3, 2018
1 parent 12c4c89 commit 434f3fc
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,16 @@ impl<K, V, S> OrderMap<K, V, S>
});
}

/// Sort the map’s key-value pairs by the default ordering of the keys
pub fn sort_keys(&mut self)
where K: Ord,
{
self.sort_by(|k1, _, k2, _| Ord::cmp(k1, k2))
}

/// Sort the map’s key-value pairs in place using the comparison
/// function `compare`; the comparison function receives two key and
/// value pairs to compare (so you can sort by keys or values).
pub fn sort_by<F>(&mut self, mut compare: F)
where F: FnMut(&K, &V, &K, &V) -> Ordering,
{
Expand Down

0 comments on commit 434f3fc

Please sign in to comment.