Trait core::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, b and c):

This trait can be used with #[derive]. When derived, it will produce a lexicographic ordering based on the top-to-bottom declaration order of the struct's members.

Required Methods

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

This method returns an Ordering between self and other.

By convention, self.cmp(&other) returns the ordering matching the expression self <operator> 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