Struct compare::Extract [] [src]

pub struct Extract<E, C> {
    // some fields omitted
}

A comparator that extracts a sort key from a value.

Examples

use compare::{Compare, Extract};
use std::cmp::Ordering::Greater;

let a = [1, 2, 3];
let b = [4, 5];

let cmp = Extract::new(|s: &[i32]| s.len());
assert_eq!(cmp.compare(&a, &b), Greater);

Methods

impl<E, K> Extract<E, Natural<K>> where K: Ord

fn new<T: ?Sized>(ext: E) -> Self where E: Fn(&T) -> K

Returns a comparator that extracts a sort key using ext and compares it according to its natural ordering.

impl<E, C> Extract<E, C>

fn with_cmp<T: ?Sized, K>(ext: E, cmp: C) -> Self where E: Fn(&T) -> K, C: Compare<K>

Returns a comparator that extracts a sort key using ext and compares it using cmp.

Trait Implementations

impl<E, C, T: ?Sized, K> Compare<T> for Extract<E, C> where E: Fn(&T) -> K, C: Compare<K>

fn compare(&self, l: &T, r: &T) -> Ordering

fn compares_lt(&self, l: &T, r: &T) -> bool

fn compares_le(&self, l: &T, r: &T) -> bool

fn compares_ge(&self, l: &T, r: &T) -> bool

fn compares_gt(&self, l: &T, r: &T) -> bool

fn compares_eq(&self, l: &T, r: &T) -> bool

fn compares_ne(&self, l: &T, r: &T) -> bool

fn borrowing(self) -> Borrowing<Self, L, R> where Self: Sized

fn rev(self) -> Rev<Self> where Self: Sized

fn swap(self) -> Swap<Self> where Self: Sized

fn then<D>(self, then: D) -> Then<Self, D> where D: Compare<L, R>, Self: Sized

Derived Implementations

impl<E: Eq, C: Eq> Eq for Extract<E, C>

impl<E: PartialEq, C: PartialEq> PartialEq for Extract<E, C>

fn eq(&self, __arg_0: &Extract<E, C>) -> bool

fn ne(&self, __arg_0: &Extract<E, C>) -> bool

impl<E: Default, C: Default> Default for Extract<E, C>

fn default() -> Extract<E, C>

impl<E: Debug, C: Debug> Debug for Extract<E, C>

fn fmt(&self, __arg_0: &mut Formatter) -> Result

impl<E: Copy, C: Copy> Copy for Extract<E, C>

impl<E: Clone, C: Clone> Clone for Extract<E, C>

fn clone(&self) -> Extract<E, C>

1.0.0fn clone_from(&mut self, source: &Self)