Trait std::cmp::Ord [] [src]

pub trait Ord: Eq + PartialOrd<Self> {
    fn cmp(&self, other: &Self) -> Ordering;
}

Trait for types that form a total order.

An order is a total order if it is (for all a`a,`, b`band` and c`c`):

Required Methods

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

This method returns an Ordering`Orderingbetween` between self`selfand` and other`other`.

By convention, self.cmp(&other)`self.cmp(&other)returns the ordering matching the expression` returns the ordering matching the expression self <operator> other`self other` if true.

Examples

fn main() { use std::cmp::Ordering; assert_eq!(5.cmp(&10), Ordering::Less); assert_eq!(10.cmp(&5), Ordering::Greater); assert_eq!(5.cmp(&5), Ordering::Equal); }
use std::cmp::Ordering;

assert_eq!(5.cmp(&10), Ordering::Less);
assert_eq!(10.cmp(&5), Ordering::Greater);
assert_eq!(5.cmp(&5), Ordering::Equal);

Implementors