The Ord and Eq comparison traits

This module contains the definition of both Ord and Eq which define the common interfaces for doing comparison. Both are language items that the compiler uses to implement the comparison operators. Rust code may implement Ord to overload the <, <=, >, and >= operators, and Eq to overload the == and != operators.

Enum Ordering

Variants

Trait ApproxEq

Trait for testing approximate equality

Method approx_epsilon

fn approx_epsilon() -> Eps

Method approx_eq

fn approx_eq(&self, other: &Self) -> bool

Method approx_eq_eps

fn approx_eq_eps(&self, other: &Self, approx_epsilon: &Eps) -> bool

Trait Eq

Trait for values that can be compared for equality and inequality.

This trait allows partial equality, where types can be unordered instead of strictly equal or unequal. For example, with the built-in floating-point types a == b and a != b will both evaluate to false if either a or b is NaN (cf. IEEE 754-2008 section 5.11).

Eventually, this will be implemented by default for types that implement TotalEq.

Method eq

fn eq(&self, other: &Self) -> bool

Method ne

fn ne(&self, other: &Self) -> bool

Trait Equiv

The equivalence relation. Two values may be equivalent even if they are of different types. The most common use case for this relation is container types; e.g. it is often desirable to be able to use &str values to look up entries in a container with ~str keys.

Method equiv

fn equiv(&self, other: &T) -> bool

Trait Ord

Trait for values that can be compared for a sort-order.

Eventually this may be simplified to only require an le method, with the others generated from default implementations. However it should remain possible to implement the others separately, for compatibility with floating-point NaN semantics (cf. IEEE 754-2008 section 5.11).

Method lt

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

Method le

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

Method ge

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

Method gt

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

Trait TotalEq

Trait for equality comparisons where a == b and a != b are strict inverses.

Method equals

fn equals(&self, other: &Self) -> bool

Trait TotalOrd

Trait for types that form a total order

Method cmp

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

Implementation of TotalEq for bool

Method equals

fn equals(&self, other: &bool) -> bool

Implementation of TotalEq for u8

Method equals

fn equals(&self, other: &u8) -> bool

Implementation of TotalEq for u16

Method equals

fn equals(&self, other: &u16) -> bool

Implementation of TotalEq for u32

Method equals

fn equals(&self, other: &u32) -> bool

Implementation of TotalEq for u64

Method equals

fn equals(&self, other: &u64) -> bool

Implementation of TotalEq for i8

Method equals

fn equals(&self, other: &i8) -> bool

Implementation of TotalEq for i16

Method equals

fn equals(&self, other: &i16) -> bool

Implementation of TotalEq for i32

Method equals

fn equals(&self, other: &i32) -> bool

Implementation of TotalEq for i64

Method equals

fn equals(&self, other: &i64) -> bool

Implementation of TotalEq for int

Method equals

fn equals(&self, other: &int) -> bool

Implementation of TotalEq for uint

Method equals

fn equals(&self, other: &uint) -> bool

Implementation of TotalEq for char

Method equals

fn equals(&self, other: &char) -> bool

Implementation of ::std::clone::Clone for Ordering

Automatically derived.

Method clone

fn clone(&self) -> Ordering

Implementation of ::std::cmp::Eq for Ordering

Automatically derived.

Method eq

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

Method ne

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

Implementation of TotalOrd for Ordering

Method cmp

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

Implementation of Ord for Ordering

Method lt

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

Method le

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

Method gt

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

Method ge

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

Implementation of TotalOrd for u8

Method cmp

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

Implementation of TotalOrd for u16

Method cmp

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

Implementation of TotalOrd for u32

Method cmp

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

Implementation of TotalOrd for u64

Method cmp

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

Implementation of TotalOrd for i8

Method cmp

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

Implementation of TotalOrd for i16

Method cmp

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

Implementation of TotalOrd for i32

Method cmp

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

Implementation of TotalOrd for i64

Method cmp

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

Implementation of TotalOrd for int

Method cmp

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

Implementation of TotalOrd for uint

Method cmp

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

Implementation of TotalOrd for char

Method cmp

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

Function cmp2

fn cmp2<A: TotalOrd, B: TotalOrd>(a1: &A, b1: &B, a2: &A, b2: &B) -> Ordering

Compares (a1, b1) against (a2, b2), where the a values are more significant.

Function lexical_ordering

fn lexical_ordering(o1: Ordering, o2: Ordering) -> Ordering

Return o1 if it is not Equal, otherwise o2. Simulates the lexical ordering on a type (int, int).

Function max

fn max<T: Ord>(v1: T, v2: T) -> T

Function min

fn min<T: Ord>(v1: T, v2: T) -> T