Trait std::cmp::PartialEq [] [src]

pub trait PartialEq<Rhs = Self> where Rhs: ?Sized {
    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, so floating point types implement PartialEq but not Eq.

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

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

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

This trait can be used with #[derive].

Required Methods

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

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

Provided Methods

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

This method tests for !=.

Implementors