Enum core::cmp::OrderingStable [-]  [+] [src]

pub enum Ordering {
    Less,
    Equal,
    Greater,
}

An ordering is, e.g, a result of a comparison between two values.

Variants

Less

An ordering where a compared value is less [than another].

Equal

An ordering where a compared value is equal [to another].

Greater

An ordering where a compared value is greater [than another].

Methods

impl Ordering

fn reverse(self) -> Ordering

Reverse the Ordering, so that Less becomes Greater and vice versa.

Example

fn main() { assert_eq!(Less.reverse(), Greater); assert_eq!(Equal.reverse(), Equal); assert_eq!(Greater.reverse(), Less); let mut data: &mut [_] = &mut [2u, 10, 5, 8]; // sort the array from largest to smallest. data.sort_by(|a, b| a.cmp(b).reverse()); let b: &mut [_] = &mut [10u, 8, 5, 2]; assert!(data == b); }
assert_eq!(Less.reverse(), Greater);
assert_eq!(Equal.reverse(), Equal);
assert_eq!(Greater.reverse(), Less);


let mut data: &mut [_] = &mut [2u, 10, 5, 8];

// sort the array from largest to smallest.
data.sort_by(|a, b| a.cmp(b).reverse());

let b: &mut [_] = &mut [10u, 8, 5, 2];
assert!(data == b);

Trait Implementations

impl Eq for Ordering

impl Ord for Ordering

fn cmp(&self, other: &Ordering) -> Ordering

impl PartialOrd for Ordering

fn partial_cmp(&self, other: &Ordering) -> Option<Ordering>

fn lt(&self, other: &Rhs) -> bool

fn le(&self, other: &Rhs) -> bool

fn gt(&self, other: &Rhs) -> bool

fn ge(&self, other: &Rhs) -> bool

Derived Implementations

impl Show for Ordering

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

impl PartialEq for Ordering

fn eq(&self, __arg_0: &Ordering) -> bool

fn ne(&self, __arg_0: &Ordering) -> bool

impl Copy for Ordering

impl Clone for Ordering

fn clone(&self) -> Ordering

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