Trait core::cmp::OrdStable [-]  [+] [src]

pub trait Ord: Eq + PartialOrd<Self> + ?Sized {
    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, b and c):

Required Methods

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

This method returns an ordering between self and other values.

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

fn main() { assert_eq!( 5u.cmp(&10), Less); // because 5 < 10 assert_eq!(10u.cmp(&5), Greater); // because 10 > 5 assert_eq!( 5u.cmp(&5), Equal); // because 5 == 5 }
assert_eq!( 5u.cmp(&10), Less);     // because 5 < 10
assert_eq!(10u.cmp(&5),  Greater);  // because 10 > 5
assert_eq!( 5u.cmp(&5),  Equal);    // because 5 == 5

Implementors