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    ///
8    /// This function calls [`slice::sort_unstable`] under the hook.
9    ///
10    /// [`slice::sort_unstable`]: https://doc.rust-lang.org/std/primitive.slice.html#method.sort_unstable
11    fn into_sorted_unstable(self) -> Self
12    where
13        Item: Ord;
14
15    /// Sort an array by a function and return it.
16    ///
17    /// This function calls [`slice::sort_unstable_by`] under the hook.
18    ///
19    /// [`slice::sort_unstable_by`]: https://doc.rust-lang.org/std/primitive.slice.html#method.sort_unstable_by
20    fn into_sorted_unstable_by<Order>(self, order: Order) -> Self
21    where
22        Order: FnMut(&Item, &Item) -> Ordering;
23
24    /// Sort an array by a key extraction function and return it.
25    ///
26    /// This function calls [`slice::sort_unstable_by_key`] under the hook.
27    ///
28    /// [`slice::sort_unstable_by_key`]: https://doc.rust-lang.org/std/primitive.slice.html#method.sort_unstable_by_key
29    fn into_sorted_unstable_by_key<Key, GetKey>(self, get_key: GetKey) -> Self
30    where
31        GetKey: FnMut(&Item) -> Key,
32        Key: Ord;
33}
34
35impl<Item, Array> IntoSortedUnstable<Item> for Array
36where
37    Array: AsMut<[Item]> + Sized,
38{
39    #[inline]
40    fn into_sorted_unstable(self) -> Self
41    where
42        Item: Ord,
43    {
44        into_sorted_unstable(self)
45    }
46
47    #[inline]
48    fn into_sorted_unstable_by<Order>(self, order: Order) -> Self
49    where
50        Order: FnMut(&Item, &Item) -> Ordering,
51    {
52        into_sorted_unstable_by(self, order)
53    }
54
55    #[inline]
56    fn into_sorted_unstable_by_key<Key, GetKey>(self, get_key: GetKey) -> Self
57    where
58        GetKey: FnMut(&Item) -> Key,
59        Key: Ord,
60    {
61        into_sorted_unstable_by_key(self, get_key)
62    }
63}