pub trait ArbitraryOrd<Rhs = Self>: PartialEq<Rhs> {
// Required method
fn arbitrary_cmp(&self, other: &Rhs) -> Ordering;
}Expand description
Trait for types that perform an arbitrary ordering.
More specifically, this trait is for types that perform either a partial or total order but semantically it is nonsensical.
§Examples
use core::cmp::Ordering;
use ordered::ArbitraryOrd;
/// A point in 2D space.
///
/// We do not want users to be able to write `a < b` because it is not well defined.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
struct Point {
x: u32,
y: u32,
}
impl ArbitraryOrd for Point {
fn arbitrary_cmp(&self, other: &Self) -> Ordering {
// Just use whatever order tuple cmp gives us.
(self.x, self.y).cmp(&(other.x, other.y))
}
}Required Methods§
Sourcefn arbitrary_cmp(&self, other: &Rhs) -> Ordering
fn arbitrary_cmp(&self, other: &Rhs) -> Ordering
Implements a meaningless, arbitrary ordering.