into_sorted/stable/
functions.rs

1use core::cmp::Ordering;
2
3/// Sort an array by [`Ord`] and return it.
4#[inline]
5pub fn into_sorted<Item, Array>(mut array: Array) -> Array
6where
7    Array: AsMut<[Item]>,
8    Item: Ord,
9{
10    array.as_mut().sort();
11    array
12}
13
14/// Sort an array by a function and return it.
15#[inline]
16pub fn into_sorted_by<Item, Array, Order>(mut array: Array, order: Order) -> Array
17where
18    Array: AsMut<[Item]>,
19    Order: FnMut(&Item, &Item) -> Ordering,
20{
21    array.as_mut().sort_by(order);
22    array
23}
24
25/// Sort an array by a key extraction function and return it.
26#[inline]
27pub fn into_sorted_by_key<Item, Array, Key, GetKey>(mut array: Array, get_key: GetKey) -> Array
28where
29    Array: AsMut<[Item]>,
30    GetKey: FnMut(&Item) -> Key,
31    Key: Ord,
32{
33    array.as_mut().sort_by_key(get_key);
34    array
35}
36
37/// Sort an array by a key extraction function (which would be called at most once per element) and return it.
38#[inline]
39pub fn into_sorted_by_cached_key<Item, Array, Key, GetKey>(
40    mut array: Array,
41    get_key: GetKey,
42) -> Array
43where
44    Array: AsMut<[Item]>,
45    GetKey: FnMut(&Item) -> Key,
46    Key: Ord,
47{
48    array.as_mut().sort_by_cached_key(get_key);
49    array
50}