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

When this trait is derived, it produces a lexicographic ordering.

This trait can be used with #[derive].

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

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