Eq in core::cmp - Rust
Description: Trait for equality comparisons which are equivalence relations.
Keywords: rust, rustlang, rust-lang, Eq

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

    pub trait Eq: PartialEq<Self> { }

Expand description

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: &Self) -> bool {
            self.isbn == other.isbn
        }
    }
    impl Eq for Book {}

Run

## Implementors

[src]

### impl Eq for !

[src]

### impl Eq for ()

1.34.0[src]

### impl Eq for Infallible

[src]

### impl Eq for FpCategory

1.55.0[src]

### impl Eq for IntErrorKind

[src]

### impl Eq for SearchStep

[src]

### impl Eq for core::sync::atomic::Ordering

[src]

### impl Eq for core::cmp::Ordering

[src]

### impl Eq for AllocError

1.28.0[src]

### impl Eq for Layout

1.50.0[src]

### impl Eq for LayoutError

[src]

### impl Eq for TypeId

1.27.0[src]

### impl Eq for CpuidResult

This is supported on x86 or x86-64 only.
1.34.0[src]

### impl Eq for CharTryFromError

1.9.0[src]

### impl Eq for DecodeUtf16Error

1.20.0[src]

### impl Eq for ParseCharError

[src]

### impl Eq for Error

1.33.0[src]

### impl Eq for PhantomPinned

1.34.0[src]

### impl Eq for NonZeroI8

1.34.0[src]

### impl Eq for NonZeroI16

1.34.0[src]

### impl Eq for NonZeroI32

1.34.0[src]

### impl Eq for NonZeroI64

1.34.0[src]

### impl Eq for NonZeroI128

1.34.0[src]

### impl Eq for NonZeroIsize

1.28.0[src]

### impl Eq for NonZeroU8

1.28.0[src]

### impl Eq for NonZeroU16

1.28.0[src]

### impl Eq for NonZeroU32

1.28.0[src]

### impl Eq for NonZeroU64

1.28.0[src]

### impl Eq for NonZeroU128

1.28.0[src]

### impl Eq for NonZeroUsize

[src]

### impl Eq for ParseFloatError

[src]

### impl Eq for ParseIntError

1.34.0[src]

### impl Eq for TryFromIntError

[src]

### impl Eq for RangeFull

[src]

### impl Eq for ParseBoolError

[src]

### impl Eq for Utf8Error

1.3.0[src]

### impl Eq for Duration

[src]

### impl Eq for FromSecsError

[src]

### impl Eq for bool

[src]

### impl Eq for char

[src]

### impl Eq for i8

[src]

### impl Eq for i16

[src]

### impl Eq for i32

[src]

### impl Eq for i64

[src]

### impl Eq for i128

[src]

### impl Eq for isize

[src]

### impl Eq for str

[src]

### impl Eq for u8

[src]

### impl Eq for u16

[src]

### impl Eq for u32

[src]

### impl Eq for u64

[src]

### impl Eq for u128

[src]

### impl Eq for usize

1.10.0[src]

### impl<'a> Eq for Location<'a>

[src]

### impl<'a> Eq for Utf8LossyChunk<'a>

[src]

### impl<A> Eq for (A,) where
A: Eq + ?Sized,

[src]

### impl<A: Eq, B> Eq for (A, B) where
B: Eq + ?Sized,

[src]

### impl<A: Eq, B: Eq, C> Eq for (A, B, C) where
C: Eq + ?Sized,

[src]

### impl<A: Eq, B: Eq, C: Eq, D> Eq for (A, B, C, D) where
D: Eq + ?Sized,

[src]

### impl<A: Eq, B: Eq, C: Eq, D: Eq, E> Eq for (A, B, C, D, E) where
E: Eq + ?Sized,

[src]

### impl<A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F> Eq for (A, B, C, D, E, F) where
F: Eq + ?Sized,

[src]

### impl<A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G> Eq for (A, B, C, D, E, F, G) where
G: Eq + ?Sized,

[src]

### impl<A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq, H> Eq for (A, B, C, D, E, F, G, H) where
H: Eq + ?Sized,

[src]

### impl<A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq, H: Eq, I> Eq for (A, B, C, D, E, F, G, H, I) where
I: Eq + ?Sized,

[src]

### impl<A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq, H: Eq, I: Eq, J> Eq for (A, B, C, D, E, F, G, H, I, J) where
J: Eq + ?Sized,

[src]

### impl<A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq, H: Eq, I: Eq, J: Eq, K> Eq for (A, B, C, D, E, F, G, H, I, J, K) where
K: Eq + ?Sized,

[src]

### 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 for (A, B, C, D, E, F, G, H, I, J, K, L) where
L: Eq + ?Sized,

[src]

### impl<A: ?Sized> Eq for &A where
A: Eq,

[src]

### impl<A: ?Sized> Eq for &mut A where
A: Eq,

[src]

### impl<Dyn: ?Sized> Eq for DynMetadata<Dyn>

1.29.0[src]

### impl<H> Eq for BuildHasherDefault<H>

[src]

### impl<Idx: Eq> Eq for Range<Idx>

[src]

### impl<Idx: Eq> Eq for RangeFrom<Idx>

1.26.0[src]

### impl<Idx: Eq> Eq for RangeInclusive<Idx>

[src]

### impl<Idx: Eq> Eq for RangeTo<Idx>

1.26.0[src]

### impl<Idx: Eq> Eq for RangeToInclusive<Idx>

1.41.0[src]

### impl<P: Deref<Target: Eq>> Eq for Pin<P>

1.4.0[src]

### impl<Ret> Eq for extern "C" fn() -> Ret

1.4.0[src]

### impl<Ret> Eq for fn() -> Ret

1.4.0[src]

### impl<Ret> Eq for unsafe extern "C" fn() -> Ret

1.4.0[src]

### impl<Ret> Eq for unsafe fn() -> Ret

1.4.0[src]

### impl<Ret, A> Eq for extern "C" fn(_: A) -> Ret

1.4.0[src]

### impl<Ret, A> Eq for extern "C" fn(_: A, ...) -> Ret

1.4.0[src]

### impl<Ret, A> Eq for fn(_: A) -> Ret

1.4.0[src]

### impl<Ret, A> Eq for unsafe extern "C" fn(_: A) -> Ret

1.4.0[src]

### impl<Ret, A> Eq for unsafe extern "C" fn(_: A, ...) -> Ret

1.4.0[src]

### impl<Ret, A> Eq for unsafe fn(_: A) -> Ret

1.4.0[src]

### impl<Ret, A, B> Eq for extern "C" fn(_: A, _: B) -> Ret

1.4.0[src]

### impl<Ret, A, B> Eq for extern "C" fn(_: A, _: B, ...) -> Ret

1.4.0[src]

### impl<Ret, A, B> Eq for fn(_: A, _: B) -> Ret

1.4.0[src]

### impl<Ret, A, B> Eq for unsafe extern "C" fn(_: A, _: B) -> Ret

1.4.0[src]

### impl<Ret, A, B> Eq for unsafe extern "C" fn(_: A, _: B, ...) -> Ret

1.4.0[src]

### impl<Ret, A, B> Eq for unsafe fn(_: A, _: B) -> Ret

1.4.0[src]

### impl<Ret, A, B, C> Eq for extern "C" fn(_: A, _: B, _: C) -> Ret

1.4.0[src]

### impl<Ret, A, B, C> Eq for extern "C" fn(_: A, _: B, _: C, ...) -> Ret

1.4.0[src]

### impl<Ret, A, B, C> Eq for fn(_: A, _: B, _: C) -> Ret

1.4.0[src]

### impl<Ret, A, B, C> Eq for unsafe extern "C" fn(_: A, _: B, _: C) -> Ret

1.4.0[src]

### impl<Ret, A, B, C> Eq for unsafe extern "C" fn(_: A, _: B, _: C, ...) -> Ret

1.4.0[src]

### impl<Ret, A, B, C> Eq for unsafe fn(_: A, _: B, _: C) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D> Eq for extern "C" fn(_: A, _: B, _: C, _: D) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D> Eq for extern "C" fn(_: A, _: B, _: C, _: D, ...) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D> Eq for fn(_: A, _: B, _: C, _: D) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, ...) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D> Eq for unsafe fn(_: A, _: B, _: C, _: D) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, ...) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E> Eq for fn(_: A, _: B, _: C, _: D, _: E) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, ...) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E> Eq for unsafe fn(_: A, _: B, _: C, _: D, _: E) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E, F> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E, F> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, ...) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E, F> Eq for fn(_: A, _: B, _: C, _: D, _: E, _: F) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E, F> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E, F> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, ...) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E, F> Eq for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E, F, G> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E, F, G> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, ...) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E, F, G> Eq for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E, F, G> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E, F, G> Eq for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, ...) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E, F, G> Eq for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E, F, G, H> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E, F, G, H> Eq for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, ...) -> Ret

1.4.0[src]

### impl<Ret, A, B, C, D, E, F, G, H> Eq for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H) -> Ret

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### impl<Ret, A, B, C, D, E, F, G, H> Eq for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H) -> Ret

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### impl<Ret, A, B, C, D, E, F, G, H, I> Eq for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I) -> Ret

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### 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

1.4.0[src]

### 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

1.21.0[src]

### impl<T> Eq for Discriminant<T>

1.2.0[src]

### impl<T: Eq + Copy> Eq for Cell<T>

1.20.0[src]

### impl<T: Eq + ?Sized> Eq for ManuallyDrop<T>

1.17.0[src]

### impl<T: Eq> Eq for Bound<T>

[src]

### impl<T: Eq> Eq for Option<T>

1.36.0[src]

### impl<T: Eq> Eq for Poll<T>

[src]

### impl<T: Eq> Eq for OnceCell<T>

[src]

### impl<T: Eq> Eq for Saturating<T>

[src]

### impl<T: Eq> Eq for Wrapping<T>

1.19.0[src]

### impl<T: Eq> Eq for Reverse<T>

[src]

### impl<T: Eq> Eq for [T]

[src]

### impl<T: Eq, E: Eq> Eq for Result<T, E>

[src]

### impl<T: Eq, const N: usize> Eq for [T; N]

1.2.0[src]

### impl<T: ?Sized + Eq> Eq for RefCell<T>

[src]

### impl<T: ?Sized> Eq for *const T

[src]

### impl<T: ?Sized> Eq for *mut T

[src]

### impl<T: ?Sized> Eq for PhantomData<T>

1.25.0[src]

### impl<T: ?Sized> Eq for NonNull<T>

[src]

### impl<Y: Eq, R: Eq> Eq for GeneratorState<Y, R>