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.
Ordering
ApproxEq
- Trait for testing approximate equalityEq
- Trait for values that can be compared for equality and inequality.Equiv
- The equivalence relationOrd
- Trait for values that can be compared for a sort-order.TotalEq
- Trait for equality comparisons where a == b
and a != b
are strict inverses.TotalOrd
- Trait for types that form a total orderof TotalEq for bool
of TotalEq for u8
of TotalEq for u16
of TotalEq for u32
of TotalEq for u64
of TotalEq for i8
of TotalEq for i16
of TotalEq for i32
of TotalEq for i64
of TotalEq for int
of TotalEq for uint
of TotalEq for char
of ::std::clone::Clone for Ordering
- Automatically derived.of ::std::cmp::Eq for Ordering
- Automatically derived.of TotalOrd for Ordering
of Ord for Ordering
of TotalOrd for u8
of TotalOrd for u16
of TotalOrd for u32
of TotalOrd for u64
of TotalOrd for i8
of TotalOrd for i16
of TotalOrd for i32
of TotalOrd for i64
of TotalOrd for int
of TotalOrd for uint
of TotalOrd for char
cmp2
- Compares (a1, b1) against (a2, b2), where the a values are more significant.lexical_ordering
- Return o1
if it is not Equal
, otherwise o2
max
min
Ordering
Less = -1
Equal = 0
Greater = 1
ApproxEq
Trait for testing approximate equality
approx_epsilon
fn approx_epsilon() -> Eps
approx_eq
fn approx_eq(&self, other: &Self) -> bool
approx_eq_eps
fn approx_eq_eps(&self, other: &Self, approx_epsilon: &Eps) -> bool
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
.
eq
fn eq(&self, other: &Self) -> bool
ne
fn ne(&self, other: &Self) -> bool
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.
equiv
fn equiv(&self, other: &T) -> bool
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).
lt
fn lt(&self, other: &Self) -> bool
le
fn le(&self, other: &Self) -> bool
ge
fn ge(&self, other: &Self) -> bool
gt
fn gt(&self, other: &Self) -> bool
TotalEq
Trait for equality comparisons where a == b
and a != b
are strict inverses.
equals
fn equals(&self, other: &Self) -> bool
TotalOrd
Trait for types that form a total order
cmp
fn cmp(&self, other: &Self) -> Ordering
TotalEq
for bool
equals
fn equals(&self, other: &bool) -> bool
TotalEq
for u8
equals
fn equals(&self, other: &u8) -> bool
TotalEq
for u16
equals
fn equals(&self, other: &u16) -> bool
TotalEq
for u32
equals
fn equals(&self, other: &u32) -> bool
TotalEq
for u64
equals
fn equals(&self, other: &u64) -> bool
TotalEq
for i8
equals
fn equals(&self, other: &i8) -> bool
TotalEq
for i16
equals
fn equals(&self, other: &i16) -> bool
TotalEq
for i32
equals
fn equals(&self, other: &i32) -> bool
TotalEq
for i64
equals
fn equals(&self, other: &i64) -> bool
TotalEq
for int
equals
fn equals(&self, other: &int) -> bool
TotalEq
for uint
equals
fn equals(&self, other: &uint) -> bool
TotalEq
for char
equals
fn equals(&self, other: &char) -> bool
::std::clone::Clone
for Ordering
Automatically derived.
clone
fn clone(&self) -> Ordering
::std::cmp::Eq
for Ordering
Automatically derived.
eq
fn eq(&self, __arg_0: &Ordering) -> ::bool
ne
fn ne(&self, __arg_0: &Ordering) -> ::bool
TotalOrd
for Ordering
cmp
fn cmp(&self, other: &Ordering) -> Ordering
Ord
for Ordering
lt
fn lt(&self, other: &Ordering) -> bool
le
fn le(&self, other: &Ordering) -> bool
gt
fn gt(&self, other: &Ordering) -> bool
ge
fn ge(&self, other: &Ordering) -> bool
TotalOrd
for u8
cmp
fn cmp(&self, other: &u8) -> Ordering
TotalOrd
for u16
cmp
fn cmp(&self, other: &u16) -> Ordering
TotalOrd
for u32
cmp
fn cmp(&self, other: &u32) -> Ordering
TotalOrd
for u64
cmp
fn cmp(&self, other: &u64) -> Ordering
TotalOrd
for i8
cmp
fn cmp(&self, other: &i8) -> Ordering
TotalOrd
for i16
cmp
fn cmp(&self, other: &i16) -> Ordering
TotalOrd
for i32
cmp
fn cmp(&self, other: &i32) -> Ordering
TotalOrd
for i64
cmp
fn cmp(&self, other: &i64) -> Ordering
TotalOrd
for int
cmp
fn cmp(&self, other: &int) -> Ordering
TotalOrd
for uint
cmp
fn cmp(&self, other: &uint) -> Ordering
TotalOrd
for char
cmp
fn cmp(&self, other: &char) -> Ordering
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.
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)
.
max
fn max<T: Ord>(v1: T, v2: T) -> T
min
fn min<T: Ord>(v1: T, v2: T) -> T