[−][src]Trait comparator::Comparator
An interface for dealing with comparators.
Required methods
Loading content...Provided methods
fn reversed(self) -> Reversed<Self> where
Self: Sized,
Self: Sized,
Reverses the Comparator
.
fn then_comparing<U>(self, other: U) -> ThenComparing<Self, U> where
Self: Sized,
U: Comparator<T>,
Self: Sized,
U: Comparator<T>,
Chains two comparators.
Returns the result of the first comparator when it's not Equal
.
Otherwise returns the result of the second comparator.
Examples
use comparator::{as_fn, comparing, natural_order, Comparator}; let mut v = [4, 2, 6, 3, 1, 5, 8, 7]; // Groups numbers by even-ness and sorts them. v.sort_by(as_fn(comparing(|i| i % 2).then_comparing(natural_order()))); assert_eq!(v, [2, 4, 6, 8, 1, 3, 5, 7]);
fn then_comparing_by_key<F, U>(self, f: F) -> ThenComparingByKey<Self, F> where
Self: Sized,
F: Fn(&T) -> U,
U: Ord,
Self: Sized,
F: Fn(&T) -> U,
U: Ord,
Chains a comparator with a key function.
Returns the result of the first comparator when it's not Equal
.
Otherwise calls f
and returns the result.
Implementors
impl<F, T> Comparator<T> for F where
F: Fn(&T, &T) -> Ordering,
T: ?Sized,
[src]
impl<F, T> Comparator<T> for F where
F: Fn(&T, &T) -> Ordering,
T: ?Sized,
fn compare(&self, a: &T, b: &T) -> Ordering | [src] |
fn reversed(self) -> Reversed<Self> where | [src] |
fn then_comparing<U>(self, other: U) -> ThenComparing<Self, U> where | [src] |
fn then_comparing_by_key<F, U>(self, f: F) -> ThenComparingByKey<Self, F> where | [src] |
impl<F, T, U> Comparator<T> for Comparing<F> where
F: Fn(&T) -> U,
T: ?Sized,
U: Ord,
[src]
impl<F, T, U> Comparator<T> for Comparing<F> where
F: Fn(&T) -> U,
T: ?Sized,
U: Ord,
fn compare(&self, a: &T, b: &T) -> Ordering | [src] |
fn reversed(self) -> Reversed<Self> where | [src] |
fn then_comparing<U>(self, other: U) -> ThenComparing<Self, U> where | [src] |
fn then_comparing_by_key<F, U>(self, f: F) -> ThenComparingByKey<Self, F> where | [src] |
impl<T, F, U, W> Comparator<U> for ThenComparingByKey<T, F> where
T: Comparator<U>,
F: Fn(&U) -> W,
U: ?Sized,
W: Ord,
[src]
impl<T, F, U, W> Comparator<U> for ThenComparingByKey<T, F> where
T: Comparator<U>,
F: Fn(&U) -> W,
U: ?Sized,
W: Ord,
fn compare(&self, a: &U, b: &U) -> Ordering | [src] |
fn reversed(self) -> Reversed<Self> where | [src] |
fn then_comparing<U>(self, other: U) -> ThenComparing<Self, U> where | [src] |
fn then_comparing_by_key<F, U>(self, f: F) -> ThenComparingByKey<Self, F> where | [src] |
impl<T, U> Comparator<U> for Reversed<T> where
T: Comparator<U>,
U: ?Sized,
[src]
impl<T, U> Comparator<U> for Reversed<T> where
T: Comparator<U>,
U: ?Sized,
fn compare(&self, a: &U, b: &U) -> Ordering | [src] |
fn reversed(self) -> Reversed<Self> where | [src] |
fn then_comparing<U>(self, other: U) -> ThenComparing<Self, U> where | [src] |
fn then_comparing_by_key<F, U>(self, f: F) -> ThenComparingByKey<Self, F> where | [src] |
impl<T, U, W> Comparator<W> for ThenComparing<T, U> where
T: Comparator<W>,
U: Comparator<W>,
W: ?Sized,
[src]
impl<T, U, W> Comparator<W> for ThenComparing<T, U> where
T: Comparator<W>,
U: Comparator<W>,
W: ?Sized,
fn compare(&self, a: &W, b: &W) -> Ordering | [src] |
fn reversed(self) -> Reversed<Self> where | [src] |
fn then_comparing<U>(self, other: U) -> ThenComparing<Self, U> where | [src] |
fn then_comparing_by_key<F, U>(self, f: F) -> ThenComparingByKey<Self, F> where | [src] |
impl<T: ?Sized> Comparator<T> for NaturalOrder where
T: Ord,
[src]
impl<T: ?Sized> Comparator<T> for NaturalOrder where
T: Ord,
fn compare(&self, a: &T, b: &T) -> Ordering | [src] |
fn reversed(self) -> Reversed<Self> where | [src] |
fn then_comparing<U>(self, other: U) -> ThenComparing<Self, U> where | [src] |
fn then_comparing_by_key<F, U>(self, f: F) -> ThenComparingByKey<Self, F> where | [src] |
impl<T: ?Sized> Comparator<T> for ReverseOrder where
T: Ord,
[src]
impl<T: ?Sized> Comparator<T> for ReverseOrder where
T: Ord,
fn compare(&self, a: &T, b: &T) -> Ordering | [src] |
fn reversed(self) -> Reversed<Self> where | [src] |
fn then_comparing<U>(self, other: U) -> ThenComparing<Self, U> where | [src] |
fn then_comparing_by_key<F, U>(self, f: F) -> ThenComparingByKey<Self, F> where | [src] |