Trait core::cmp::PartialOrd
[−]
[src]
pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>;
fn lt(&self, other: &Rhs) -> bool { ... }
fn le(&self, other: &Rhs) -> bool { ... }
fn gt(&self, other: &Rhs) -> bool { ... }
fn ge(&self, other: &Rhs) -> bool { ... }
}Trait for values that can be compared for a sort-order.
The comparison must satisfy, for all a`a,`, b`band` and c`c`:
- antisymmetry: if
a < b`a < bthen` then!(a > b)`!(a > b)` and vice versa; and - transitivity:
a < b`a < band` andb < c`b < cimplies` impliesa < c`a < c. The same must hold for both`. The same must hold for both==`==and` and>`>`.
Note that these requirements mean that the trait itself must be implemented symmetrically and
transitively: if T: PartialOrd<U>`T: PartialOrdand` and U: PartialOrd<V>`U: PartialOrdthen` then U: PartialOrd<T>`U: PartialOrdand` and T: PartialOrd<V>`T:
PartialOrd
PartialOrd only requires implementation of the partial_cmp`partial_cmp` method, with the others generated
from default implementations.
However it remains possible to implement the others separately for types which do not have a
total order. For example, for floating point numbers, NaN < 0 == false`NaN < 0 == falseand` and NaN >= 0 == false`NaN >= 0 ==
false` (cf. IEEE 754-2008 section 5.11).
Required Methods
fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>
This method returns an ordering between self`selfand` and other`other` values if one exists.
Examples
fn main() { use std::cmp::Ordering; let result = 1.0.partial_cmp(&2.0); assert_eq!(result, Some(Ordering::Less)); let result = 1.0.partial_cmp(&1.0); assert_eq!(result, Some(Ordering::Equal)); let result = 2.0.partial_cmp(&1.0); assert_eq!(result, Some(Ordering::Greater)); }use std::cmp::Ordering; let result = 1.0.partial_cmp(&2.0); assert_eq!(result, Some(Ordering::Less)); let result = 1.0.partial_cmp(&1.0); assert_eq!(result, Some(Ordering::Equal)); let result = 2.0.partial_cmp(&1.0); assert_eq!(result, Some(Ordering::Greater));
When comparison is impossible:
fn main() { let result = std::f64::NAN.partial_cmp(&1.0); assert_eq!(result, None); }let result = std::f64::NAN.partial_cmp(&1.0); assert_eq!(result, None);
Provided Methods
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self`selfand` and other`other) and is used by the`) and is used by the <`<` operator.
Examples
fn main() { use std::cmp::Ordering; let result = 1.0 < 2.0; assert_eq!(result, true); let result = 2.0 < 1.0; assert_eq!(result, false); }use std::cmp::Ordering; let result = 1.0 < 2.0; assert_eq!(result, true); let result = 2.0 < 1.0; assert_eq!(result, false);
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self`selfand` and other`other) and is used by the`) and is used by the <=`<=`
operator.
Examples
fn main() { let result = 1.0 <= 2.0; assert_eq!(result, true); let result = 2.0 <= 2.0; assert_eq!(result, true); }let result = 1.0 <= 2.0; assert_eq!(result, true); let result = 2.0 <= 2.0; assert_eq!(result, true);
fn gt(&self, other: &Rhs) -> bool
This method tests greater than (for self`selfand` and other`other) and is used by the`) and is used by the >`>` operator.
Examples
fn main() { let result = 1.0 > 2.0; assert_eq!(result, false); let result = 2.0 > 2.0; assert_eq!(result, false); }let result = 1.0 > 2.0; assert_eq!(result, false); let result = 2.0 > 2.0; assert_eq!(result, false);
fn ge(&self, other: &Rhs) -> bool
This method tests greater than or equal to (for self`selfand` and other`other) and is used by the`) and is used by the >=`>=`
operator.
Examples
fn main() { let result = 2.0 >= 1.0; assert_eq!(result, true); let result = 2.0 >= 2.0; assert_eq!(result, true); }let result = 2.0 >= 1.0; assert_eq!(result, true); let result = 2.0 >= 2.0; assert_eq!(result, true);
Implementors
impl<T: PartialOrd> PartialOrd for Wrapping<T> where T: PartialOrdimpl<T: PartialOrd + Zeroable> PartialOrd for NonZero<T> where T: PartialOrdimpl<T: ?Sized> PartialOrd for *const Timpl<T: ?Sized> PartialOrd for *mut Timpl PartialOrd for NoCopyimpl<T: ?Sized> PartialOrd for PhantomData<T>impl PartialOrd for ()impl PartialOrd for boolimpl PartialOrd for charimpl PartialOrd for usizeimpl PartialOrd for u8impl PartialOrd for u16impl PartialOrd for u32impl PartialOrd for u64impl PartialOrd for isizeimpl PartialOrd for i8impl PartialOrd for i16impl PartialOrd for i32impl PartialOrd for i64impl PartialOrd for f32impl PartialOrd for f64impl<'a, 'b, A: ?Sized, B: ?Sized> PartialOrd<&'b B> for &'a A where A: PartialOrd<B>impl<'a, 'b, A: ?Sized, B: ?Sized> PartialOrd<&'b mut B> for &'a mut A where A: PartialOrd<B>impl PartialOrd for Orderingimpl<T: PartialOrd> PartialOrd for [T; 0]impl<T: PartialOrd> PartialOrd for [T; 1]impl<T: PartialOrd> PartialOrd for [T; 2]impl<T: PartialOrd> PartialOrd for [T; 3]impl<T: PartialOrd> PartialOrd for [T; 4]impl<T: PartialOrd> PartialOrd for [T; 5]impl<T: PartialOrd> PartialOrd for [T; 6]impl<T: PartialOrd> PartialOrd for [T; 7]impl<T: PartialOrd> PartialOrd for [T; 8]impl<T: PartialOrd> PartialOrd for [T; 9]impl<T: PartialOrd> PartialOrd for [T; 10]impl<T: PartialOrd> PartialOrd for [T; 11]impl<T: PartialOrd> PartialOrd for [T; 12]impl<T: PartialOrd> PartialOrd for [T; 13]impl<T: PartialOrd> PartialOrd for [T; 14]impl<T: PartialOrd> PartialOrd for [T; 15]impl<T: PartialOrd> PartialOrd for [T; 16]impl<T: PartialOrd> PartialOrd for [T; 17]impl<T: PartialOrd> PartialOrd for [T; 18]impl<T: PartialOrd> PartialOrd for [T; 19]impl<T: PartialOrd> PartialOrd for [T; 20]impl<T: PartialOrd> PartialOrd for [T; 21]impl<T: PartialOrd> PartialOrd for [T; 22]impl<T: PartialOrd> PartialOrd for [T; 23]impl<T: PartialOrd> PartialOrd for [T; 24]impl<T: PartialOrd> PartialOrd for [T; 25]impl<T: PartialOrd> PartialOrd for [T; 26]impl<T: PartialOrd> PartialOrd for [T; 27]impl<T: PartialOrd> PartialOrd for [T; 28]impl<T: PartialOrd> PartialOrd for [T; 29]impl<T: PartialOrd> PartialOrd for [T; 30]impl<T: PartialOrd> PartialOrd for [T; 31]impl<T: PartialOrd> PartialOrd for [T; 32]impl<T: PartialOrd> PartialOrd for Option<T> where T: PartialOrdimpl<T: PartialOrd, E: PartialOrd> PartialOrd for Result<T, E> where T: PartialOrd, E: PartialOrdimpl<T: PartialOrd> PartialOrd for [T]impl PartialOrd for strimpl<A: PartialOrd + PartialEq> PartialOrd for (A,)impl<A: PartialOrd + PartialEq, B: PartialOrd + PartialEq> PartialOrd for (A, B)impl<A: PartialOrd + PartialEq, B: PartialOrd + PartialEq, C: PartialOrd + PartialEq> PartialOrd for (A, B, C)impl<A: PartialOrd + PartialEq, B: PartialOrd + PartialEq, C: PartialOrd + PartialEq, D: PartialOrd + PartialEq> PartialOrd for (A, B, C, D)impl<A: PartialOrd + PartialEq, B: PartialOrd + PartialEq, C: PartialOrd + PartialEq, D: PartialOrd + PartialEq, E: PartialOrd + PartialEq> PartialOrd for (A, B, C, D, E)impl<A: PartialOrd + PartialEq, B: PartialOrd + PartialEq, C: PartialOrd + PartialEq, D: PartialOrd + PartialEq, E: PartialOrd + PartialEq, F: PartialOrd + PartialEq> PartialOrd for (A, B, C, D, E, F)impl<A: PartialOrd + PartialEq, B: PartialOrd + PartialEq, C: PartialOrd + PartialEq, D: PartialOrd + PartialEq, E: PartialOrd + PartialEq, F: PartialOrd + PartialEq, G: PartialOrd + PartialEq> PartialOrd for (A, B, C, D, E, F, G)impl<A: PartialOrd + PartialEq, B: PartialOrd + PartialEq, C: PartialOrd + PartialEq, D: PartialOrd + PartialEq, E: PartialOrd + PartialEq, F: PartialOrd + PartialEq, G: PartialOrd + PartialEq, H: PartialOrd + PartialEq> PartialOrd for (A, B, C, D, E, F, G, H)impl<A: PartialOrd + PartialEq, B: PartialOrd + PartialEq, C: PartialOrd + PartialEq, D: PartialOrd + PartialEq, E: PartialOrd + PartialEq, F: PartialOrd + PartialEq, G: PartialOrd + PartialEq, H: PartialOrd + PartialEq, I: PartialOrd + PartialEq> PartialOrd for (A, B, C, D, E, F, G, H, I)impl<A: PartialOrd + PartialEq, B: PartialOrd + PartialEq, C: PartialOrd + PartialEq, D: PartialOrd + PartialEq, E: PartialOrd + PartialEq, F: PartialOrd + PartialEq, G: PartialOrd + PartialEq, H: PartialOrd + PartialEq, I: PartialOrd + PartialEq, J: PartialOrd + PartialEq> PartialOrd for (A, B, C, D, E, F, G, H, I, J)impl<A: PartialOrd + PartialEq, B: PartialOrd + PartialEq, C: PartialOrd + PartialEq, D: PartialOrd + PartialEq, E: PartialOrd + PartialEq, F: PartialOrd + PartialEq, G: PartialOrd + PartialEq, H: PartialOrd + PartialEq, I: PartialOrd + PartialEq, J: PartialOrd + PartialEq, K: PartialOrd + PartialEq> PartialOrd for (A, B, C, D, E, F, G, H, I, J, K)impl<A: PartialOrd + PartialEq, B: PartialOrd + PartialEq, C: PartialOrd + PartialEq, D: PartialOrd + PartialEq, E: PartialOrd + PartialEq, F: PartialOrd + PartialEq, G: PartialOrd + PartialEq, H: PartialOrd + PartialEq, I: PartialOrd + PartialEq, J: PartialOrd + PartialEq, K: PartialOrd + PartialEq, L: PartialOrd + PartialEq> PartialOrd for (A, B, C, D, E, F, G, H, I, J, K, L)