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
Eq
- 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 ::core::cmp::Eq 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
eq
ge
gt
le
lt
max
min
ne
Ordering
Less
Equal
Greater
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
::core::cmp::Eq
for Ordering
eq
fn eq(&self, __other: &Ordering) -> bool
ne
fn ne(&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
eq
fn eq<T: Eq>(v1: &T, v2: &T) -> bool
ge
fn ge<T: Ord>(v1: &T, v2: &T) -> bool
gt
fn gt<T: Ord>(v1: &T, v2: &T) -> bool
le
fn le<T: Ord>(v1: &T, v2: &T) -> bool
lt
fn lt<T: Ord>(v1: &T, v2: &T) -> bool
max
fn max<T: Ord>(v1: T, v2: T) -> T
min
fn min<T: Ord>(v1: T, v2: T) -> T
ne
fn ne<T: Eq>(v1: &T, v2: &T) -> bool