docs

core::cmp

On this page

total equality, ordering and hashing. PartialEq / PartialOrd carry the comparison operators and stay with the other operator traits in ops.nabi. Eq is a pure marker with no methods, so it has no slot.

Enums

OrderingSource

pub enum Ordering

The result of a three-way comparison.

  • Greater§

    Source
  • pub const fn is_lt(self) -> bool§

    Source

    true for Less.

  • pub const fn is_eq(self) -> bool§

    Source

    true for Equal.

  • pub const fn is_gt(self) -> bool§

    Source

    true for Greater.

  • pub const fn reverse(self) -> Ordering§

    Source

    Less and Greater swapped; Equal stays.

  • pub const fn then(self, other: Ordering) -> Ordering§

    Source

    self unless it is Equal, then other: a tie-break, a.0.cmp(b.0).then(a.1.cmp(b.1)).

  • pub fn then_with(self, f: fn() -> Ordering) -> Ordering§

    Source

    self unless it is Equal, then f(): a tie-break computed only on a tie.

Trait implementations 1

Traits

EqSource

pub trait Eq: PartialEq

Total equality: == is reflexive, symmetric and transitive (no NaN). A marker over PartialEq with no methods.

OrdSource

pub trait Ord: PartialOrd + Eq

A total order.

  • fn cmp(self, rhs: Self) -> Ordering§

    Source

    Compares self with rhs: Less, Equal or Greater.

  • const fn min(self, rhs: Self) -> Self§

    Source

    The smaller of self and rhs; self when they are equal.

  • const fn max(self, rhs: Self) -> Self§

    Source

    The larger of self and rhs; rhs when they are equal.

  • const fn clamp(self, low: Self, high: Self) -> Self§

    Source

    low when self is below it, high when above it, else self. Panics when low > high.

HashSource

pub trait Hash: Eq

Feeds a value to a Hasher: equal values make the same writes, so a == b hashes alike - what Dict / Set rely on.

  • fn hash<H: Hasher>(self, ref h: H)§

    Source

    The hash of self; equal values hash equal.