Trait Sorter

Source
pub trait Sorter<R> {
    // Required method
    fn compare(&self, a: &R, b: &R) -> Ordering;

    // Provided methods
    fn sort_vec(&self, vec: &mut Vec<R>) { ... }
    fn sort_ref_vec(&self, vec: &mut Vec<&R>) { ... }
}
Available on crate feature sort only.
Expand description

Compare two values of another type R.

While Ord is a sensible trait for types that can have only one ordering, it needs to be generalised when a type can have multiple orderings according to some parameterisation. Sorter is just that generalisation.

Required Methods§

Source

fn compare(&self, a: &R, b: &R) -> Ordering

Compare two elements, returning an Ordering.

This is essentially the equivalent of implementing cmp for another type.

Provided Methods§

Source

fn sort_vec(&self, vec: &mut Vec<R>)

Sort a Vec in place.

Source

fn sort_ref_vec(&self, vec: &mut Vec<&R>)

Sort a Vec of references in place.

Implementors§