into_sorted/unstable/
methods.rs

1use super::functions::*;
2use core::cmp::Ordering;
3
4/// Utility methods to sort various types of arrays with an unstable algorithm.
5pub trait IntoSortedUnstable<Item>: crate::sealed::IsArray<Item> {
6    /// Sort an array by [`Ord`] and return it.
7    fn into_sorted_unstable(self) -> Self
8    where
9        Item: Ord;
10
11    /// Sort an array by a function and return it.
12    fn into_sorted_unstable_by<Order>(self, order: Order) -> Self
13    where
14        Order: FnMut(&Item, &Item) -> Ordering;
15
16    /// Sort an array by a key extraction function and return it.
17    fn into_sorted_unstable_by_key<Key, GetKey>(self, get_key: GetKey) -> Self
18    where
19        GetKey: FnMut(&Item) -> Key,
20        Key: Ord;
21}
22
23impl<Item, Array> IntoSortedUnstable<Item> for Array
24where
25    Array: AsMut<[Item]> + Sized,
26{
27    #[inline]
28    fn into_sorted_unstable(self) -> Self
29    where
30        Item: Ord,
31    {
32        into_sorted_unstable(self)
33    }
34
35    #[inline]
36    fn into_sorted_unstable_by<Order>(self, order: Order) -> Self
37    where
38        Order: FnMut(&Item, &Item) -> Ordering,
39    {
40        into_sorted_unstable_by(self, order)
41    }
42
43    #[inline]
44    fn into_sorted_unstable_by_key<Key, GetKey>(self, get_key: GetKey) -> Self
45    where
46        GetKey: FnMut(&Item) -> Key,
47        Key: Ord,
48    {
49        into_sorted_unstable_by_key(self, get_key)
50    }
51}