std::cmp::Eq - Rust (original) (raw)

Trait std::cmp::Eq1.0.0 [โˆ’] [src]

pub trait Eq: PartialEq { }

Trait for equality comparisons which are equivalence relations.

This means, that in addition to a == b and a != b being strict inverses, the equality must be (for all a, b and c):

This property cannot be checked by the compiler, and therefore Eq impliesPartialEq, and has no extra methods.

This trait can be used with #[derive]. When derived, because Eq has no extra methods, it is only informing the compiler that this is an equivalence relation rather than a partial equivalence relation. Note that the derive strategy requires all fields are Eq, which isn't always desired.

If you cannot use the derive strategy, specify that your type implementsEq, which has no methods:

enum BookFormat { Paperback, Hardback, Ebook } struct Book { isbn: i32, format: BookFormat, } impl PartialEq for Book { fn eq(&self, other: &Book) -> bool { self.isbn == other.isbn } } impl Eq for Book {}Run

impl [Eq](../../std/cmp/trait.Eq.html "trait std::cmp::Eq") for [InvalidSequence](../../core/char/struct.InvalidSequence.html "struct core::char::InvalidSequence")[src]

`impl Eq for NonZero where

T: Zeroable + Eq, `[src]

impl<'a> [Eq](../../std/cmp/trait.Eq.html "trait std::cmp::Eq") for [Utf8LossyChunk](../../std%5Funicode/lossy/struct.Utf8LossyChunk.html "struct std_unicode::lossy::Utf8LossyChunk")<'a>[src]