Skip to content

Commit bd45ae9

Browse files
committed
test: into_sorted_by_key
1 parent 41010c2 commit bd45ae9

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

tests/_utils.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@ pub trait IntoSorted<Item>: Sized {
343343
fn into_sorted_by<Order>(self, order: Order) -> Self
344344
where
345345
Order: FnMut(&Item, &Item) -> Ordering;
346+
347+
/// Sort an array by a key extraction function and return it.
348+
fn into_sorted_by_key<Key, GetKey>(self, get_key: GetKey) -> Self
349+
where
350+
GetKey: FnMut(&Item) -> Key,
351+
Key: Ord;
346352
}
347353

348354
impl<Item, Array> IntoSorted<Item> for Array
@@ -364,4 +370,13 @@ where
364370
self.as_mut().sort_by(order);
365371
self
366372
}
373+
374+
fn into_sorted_by_key<Key, GetKey>(mut self, get_key: GetKey) -> Self
375+
where
376+
GetKey: FnMut(&Item) -> Key,
377+
Key: Ord,
378+
{
379+
self.as_mut().sort_by_key(get_key);
380+
self
381+
}
367382
}

0 commit comments

Comments
 (0)