core::cmp::Eq - Rust
Description: API documentation for the Rust `Eq` trait in crate `core`.
Keywords: rust, rustlang, rust-lang, Eq

# Trait core::cmp::Eq 1.0.0 [−] [src]

    pub trait Eq: PartialEq<Self> { }

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`):

- reflexive: `a == a`;
- symmetric: `a == b` implies `b == a`; and
- transitive: `a == b` and `b == c` implies `a == c`.

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

## Derivable

This trait can be used with `#[derive]`. When `derive`d, 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.

## How can I implement `Eq`?

If you cannot use the `derive` strategy, specify that your type implements `Eq`, 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

## Implementors

- [src]
  `impl Eq for ParseFloatError`
- [src]
  `impl<T: Eq> Eq for Wrapping<T>`
- [src]
  `impl Eq for FpCategory`
- [src]
  `impl Eq for ParseIntError`
- [src]
  `impl<T> Eq for Discriminant<T>`
- [src]
  `impl<T: Eq> Eq for ManuallyDrop<T>`
- [src]
  `impl<T: Eq + Zeroable> Eq for NonZero<T>`
- `impl<T: ?Sized> Eq for *const T`
- `impl<T: ?Sized> Eq for *mut T`
- `impl<Ret> Eq for fn() -> Ret`
- `impl<Ret> Eq for extern "C" fn() -> Ret`
- `impl<Ret> Eq for unsafe fn() -> Ret`
- `impl<Ret> Eq for unsafe extern "C" fn() -> Ret`
- `impl<Ret, A> Eq for fn(_: A) -> Ret`
- `impl<Ret, A> Eq for extern "C" fn(_: A) -> Ret`
- `impl<Ret, A> Eq for extern "C" fn(_: A, ...) -> Ret`
- `impl<Ret, A> Eq for unsafe fn(_: A) -> Ret`
- `impl<Ret, A> Eq for unsafe extern "C" fn(_: A) -> Ret`
- `impl<Ret, A> Eq for unsafe extern "C" fn(_: A, ...) -> Ret`
- `impl<Ret, A, B> Eq for fn(_: A, _: B) -> Ret`
- `impl<Ret, A, B> Eq for extern "C" fn(_: A, _: B) -> Ret`
- `impl<Ret, A, B> Eq for extern "C" fn(_: A, _: B, ...) -> Ret`
- `impl<Ret, A, B> Eq for unsafe fn(_: A, _: B) -> Ret`
- `impl<Ret, A, B> Eq for unsafe extern "C" fn(_: A, _: B) -> Ret`
- `impl<Ret, A, B> Eq for unsafe extern "C" fn(_: A, _: B, ...) -> Ret`
- `impl<Ret, A, B, C> Eq for fn(_: A, _: B, _: C) -> Ret`
- `impl<Ret, A, B, C> Eq for extern "C" fn(_: A, _: B, _: C) -> Ret`
- `impl<Ret, A, B, C> Eq for extern "C" fn(_: A, _: B, _: C, ...) -> Ret`
- `impl<Ret, A, B, C> Eq for unsafe fn(_: A, _: B, _: C) -> Ret`
- `impl<Ret, A, B, C> Eq for unsafe extern "C" fn(_: A, _: B, _: C) -> Ret`
- `impl<Ret, A, B, C> Eq for unsafe extern "C" fn(_: A, _: B, _: C, ...) -> Ret`
- `impl<Ret, A, B, C, D> Eq for fn(_: A, _: B, _: C, _: D) -> Ret`
- `impl<Ret, A, B, C, D> Eq for extern "C" fn(_: A, _: B, _: C, _: D) -> Ret`
- `impl<Ret, A, B, C, D> Eq for extern "C" fn(_: A, _: B, _: C, _: D, ...) -> Ret`
- `impl<Ret, A, B, C, D> Eq for unsafe fn(_: A, _: B, _: C, _: D) -> Ret`
- `impl<Ret, A, B, C, D> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D) -> Ret`
- `impl<Ret, A, B, C, D> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, ...) -> Ret`
- `impl<Ret, A, B, C, D, E> Eq for fn(_: A, _: B, _: C, _: D, _: E) -> Ret`
- `impl<Ret, A, B, C, D, E> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E) -> Ret`
- `impl<Ret, A, B, C, D, E> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, ...) -> Ret`
- `impl<Ret, A, B, C, D, E> Eq for unsafe fn(_: A, _: B, _: C, _: D, _: E) -> Ret`
- `impl<Ret, A, B, C, D, E> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E) -> Ret`
- `impl<Ret, A, B, C, D, E> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, ...) -> Ret`
- `impl<Ret, A, B, C, D, E, F> Eq for fn(_: A, _: B, _: C, _: D, _: E, _: F) -> Ret`
- `impl<Ret, A, B, C, D, E, F> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F) -> Ret`
- `impl<Ret, A, B, C, D, E, F> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, ...) -> Ret`
- `impl<Ret, A, B, C, D, E, F> Eq for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F) -> Ret`
- `impl<Ret, A, B, C, D, E, F> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F) -> Ret`
- `impl<Ret, A, B, C, D, E, F> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, ...) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G> Eq for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, ...) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G> Eq for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, ...) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H> Eq for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, ...) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H> Eq for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, ...) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I> Eq for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, ...) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I> Eq for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, ...) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I, J> Eq for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I, J> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I, J> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, ...) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I, J> Eq for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I, J> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I, J> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, ...) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Eq for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K, ...) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Eq for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K, ...) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Eq for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K, _: L) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K, _: L) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K, _: L, ...) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Eq for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K, _: L) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K, _: L) -> Ret`
- `impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K, _: L, ...) -> Ret`
- [src]
  `impl<T: ?Sized> Eq for PhantomData<T>`
- [src]
  `impl<Y: Eq, R: Eq> Eq for GeneratorState<Y, R>`
- [src]
  `impl Eq for RangeFull`
- [src]
  `impl<Idx: Eq> Eq for Range<Idx>`
- [src]
  `impl<Idx: Eq> Eq for RangeFrom<Idx>`
- [src]
  `impl<Idx: Eq> Eq for RangeTo<Idx>`
- [src]
  `impl<Idx: Eq> Eq for RangeInclusive<Idx>`
- [src]
  `impl<Idx: Eq> Eq for RangeToInclusive<Idx>`
- `impl Eq for ()`
- `impl Eq for bool`
- `impl Eq for char`
- `impl Eq for usize`
- `impl Eq for u8`
- `impl Eq for u16`
- `impl Eq for u32`
- `impl Eq for u64`
- `impl Eq for u128`
- `impl Eq for isize`
- `impl Eq for i8`
- `impl Eq for i16`
- `impl Eq for i32`
- `impl Eq for i64`
- `impl Eq for i128`
- `impl Eq for !`
- `impl<'a, A: ?Sized> Eq for &'a A where
  A: Eq,`
- `impl<'a, A: ?Sized> Eq for &'a mut A where
  A: Eq,`
- [src]
  `impl<T: Eq> Eq for Reverse<T>`
- [src]
  `impl Eq for Ordering`
- [src]
  `impl Eq for Infallible`
- [src]
  `impl Eq for TypeId`
- `impl<T: Eq> Eq for [T; 0]`
- `impl<T: Eq> Eq for [T; 1]`
- `impl<T: Eq> Eq for [T; 2]`
- `impl<T: Eq> Eq for [T; 3]`
- `impl<T: Eq> Eq for [T; 4]`
- `impl<T: Eq> Eq for [T; 5]`
- `impl<T: Eq> Eq for [T; 6]`
- `impl<T: Eq> Eq for [T; 7]`
- `impl<T: Eq> Eq for [T; 8]`
- `impl<T: Eq> Eq for [T; 9]`
- `impl<T: Eq> Eq for [T; 10]`
- `impl<T: Eq> Eq for [T; 11]`
- `impl<T: Eq> Eq for [T; 12]`
- `impl<T: Eq> Eq for [T; 13]`
- `impl<T: Eq> Eq for [T; 14]`
- `impl<T: Eq> Eq for [T; 15]`
- `impl<T: Eq> Eq for [T; 16]`
- `impl<T: Eq> Eq for [T; 17]`
- `impl<T: Eq> Eq for [T; 18]`
- `impl<T: Eq> Eq for [T; 19]`
- `impl<T: Eq> Eq for [T; 20]`
- `impl<T: Eq> Eq for [T; 21]`
- `impl<T: Eq> Eq for [T; 22]`
- `impl<T: Eq> Eq for [T; 23]`
- `impl<T: Eq> Eq for [T; 24]`
- `impl<T: Eq> Eq for [T; 25]`
- `impl<T: Eq> Eq for [T; 26]`
- `impl<T: Eq> Eq for [T; 27]`
- `impl<T: Eq> Eq for [T; 28]`
- `impl<T: Eq> Eq for [T; 29]`
- `impl<T: Eq> Eq for [T; 30]`
- `impl<T: Eq> Eq for [T; 31]`
- `impl<T: Eq> Eq for [T; 32]`
- [src]
  `impl<T: Eq + Copy> Eq for Cell<T>`
- [src]
  `impl<T: ?Sized + Eq> Eq for RefCell<T>`
- [src]
  `impl Eq for CharTryFromError`
- [src]
  `impl Eq for InvalidSequence`
- [src]
  `impl<T: Eq> Eq for Option<T>`
- [src]
  `impl Eq for NoneError`
- [src]
  `impl<T: Eq, E: Eq> Eq for Result<T, E>`
- `impl<T: Eq> Eq for [T]`
- [src]
  `impl Eq for SearchStep`
- `impl Eq for str`
- [src]
  `impl Eq for ParseBoolError`
- [src]
  `impl Eq for Utf8Error`
- [src]
  `impl Eq for Error`
- `impl<A: Eq + ?Sized> Eq for (A,) where
  A: ,`
- `impl<A: Eq, B: Eq + ?Sized> Eq for (A, B) where
  B: ,`
- `impl<A: Eq, B: Eq, C: Eq + ?Sized> Eq for (A, B, C) where
  C: ,`
- `impl<A: Eq, B: Eq, C: Eq, D: Eq + ?Sized> Eq for (A, B, C, D) where
  D: ,`
- `impl<A: Eq, B: Eq, C: Eq, D: Eq, E: Eq + ?Sized> Eq for (A, B, C, D, E) where
  E: ,`
- `impl<A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq + ?Sized> Eq for (A, B, C, D, E, F) where
  F: ,`
- `impl<A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq + ?Sized> Eq for (A, B, C, D, E, F, G) where
  G: ,`
- `impl<A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq, H: Eq + ?Sized> Eq for (A, B, C, D, E, F, G, H) where
  H: ,`
- `impl<A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq, H: Eq, I: Eq + ?Sized> Eq for (A, B, C, D, E, F, G, H, I) where
  I: ,`
- `impl<A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq, H: Eq, I: Eq, J: Eq + ?Sized> Eq for (A, B, C, D, E, F, G, H, I, J) where
  J: ,`
- `impl<A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq, H: Eq, I: Eq, J: Eq, K: Eq + ?Sized> Eq for (A, B, C, D, E, F, G, H, I, J, K) where
  K: ,`
- `impl<A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq, H: Eq, I: Eq, J: Eq, K: Eq, L: Eq + ?Sized> Eq for (A, B, C, D, E, F, G, H, I, J, K, L) where
  L: ,`

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result
+
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)