Skip to content

refactor: make IntoSorted an actual crate and reuse it here #298

@KSXGitHub

Description

@KSXGitHub

Relevant commit: 2b3fcf1

/// Utility methods to sort various types of arrays.
pub trait IntoSorted<Item>: Sized {
/// Sort an array by [`Ord`] and return it.
fn into_sorted(self) -> Self
where
Item: Ord;
/// Sort an array by a function and return it.
fn into_sorted_by<Order>(self, order: Order) -> Self
where
Order: FnMut(&Item, &Item) -> Ordering;
}
impl<Item, Array> IntoSorted<Item> for Array
where
Array: AsMut<[Item]> + Sized,
{
fn into_sorted(mut self) -> Self
where
Item: Ord,
{
self.as_mut().sort();
self
}
fn into_sorted_by<Order>(mut self, order: Order) -> Self
where
Order: FnMut(&Item, &Item) -> Ordering,
{
self.as_mut().sort_by(order);
self
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions