Trait core::cmp::PartialEq [] [src]

pub trait PartialEq<Rhs: ?Sized = Self> {
    fn eq(&self, other: &Rhs) -> bool;

    fn ne(&self, other: &Rhs) -> bool { ... }
}

Trait for equality comparisons which are partial equivalence relations.

This trait allows for partial equality, for types that do not have a full equivalence relation. For example, in floating point numbers NaN != NaN`NaN != NaN, so floating point types implement`, so floating point types implement PartialEq`PartialEqbut not` but not Eq`Eq`.

Formally, the equality must be (for all a`a,`, b`band` and c`c`):

Note that these requirements mean that the trait itself must be implemented symmetrically and transitively: if T: PartialEq<U>`T: PartialEqand` and U: PartialEq<V>`U: PartialEqthen` then U: PartialEq<T>`U: PartialEqand` and T: PartialEq<V>`T: PartialEq`.

PartialEq only requires the eq`eqmethod to be implemented;` method to be implemented; ne`neis defined in terms of it by default. Any manual implementation of` is defined in terms of it by default. Any manual implementation of ne`ne*must* respect the rule that` must respect the rule that eq`eqis a strict inverse of` is a strict inverse of ne`ne; that is,`; that is, !(a == b)`!(a == b)if and only if` if and only if a != b`a != b`.

Required Methods

fn eq(&self, other: &Rhs) -> bool

This method tests for self`selfand` and other`othervalues to be equal, and is used by` values to be equal, and is used by ==`==`.

Provided Methods

fn ne(&self, other: &Rhs) -> bool

This method tests for !=`!=`.

Implementors