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
impliesb == a
; and - transitive:
a == b
andb == c
impliesa == 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 {}
RunImplementors
impl Eq for Infallible
impl Eq for Alignment
impl Eq for FpCategory
impl Eq for IntErrorKind
impl Eq for Which
impl Eq for SearchStep
impl Eq for core::sync::atomic::Ordering
impl Eq for core::cmp::Ordering
impl Eq for bool
impl Eq for char
impl Eq for i8
impl Eq for i16
impl Eq for i32
impl Eq for i64
impl Eq for i128
impl Eq for isize
impl Eq for !
impl Eq for str
impl Eq for u8
impl Eq for u16
impl Eq for u32
impl Eq for u64
impl Eq for u128
impl Eq for ()
impl Eq for usize
impl Eq for AllocError
impl Eq for Layout
impl Eq for LayoutError
impl Eq for TypeId
impl Eq for CpuidResult
Available on x86 or x86-64 only.
impl Eq for CharTryFromError
impl Eq for DecodeUtf16Error
impl Eq for ParseCharError
impl Eq for TryFromCharError
impl Eq for CStr
impl Eq for FromBytesUntilNulError
impl Eq for FromBytesWithNulError
impl Eq for Error
impl Eq for PhantomPinned
impl Eq for NonZeroI8
impl Eq for NonZeroI16
impl Eq for NonZeroI32
impl Eq for NonZeroI64
impl Eq for NonZeroI128
impl Eq for NonZeroIsize
impl Eq for NonZeroU8
impl Eq for NonZeroU16
impl Eq for NonZeroU32
impl Eq for NonZeroU64
impl Eq for NonZeroU128
impl Eq for NonZeroUsize
impl Eq for ParseFloatError
impl Eq for ParseIntError
impl Eq for TryFromIntError
impl Eq for RangeFull
impl Eq for ParseBoolError
impl Eq for Utf8Error
impl Eq for Duration
impl Eq for FromFloatSecsError
impl<'a> Eq for Location<'a>
impl<'a> Eq for Utf8LossyChunk<'a>
impl<A: ?Sized> Eq for &A where
A: Eq,
impl<A: ?Sized> Eq for &mut A where
A: Eq,
impl<Dyn: ?Sized> Eq for DynMetadata<Dyn>
impl<H> Eq for BuildHasherDefault<H>
impl<Idx: Eq> Eq for Range<Idx>
impl<Idx: Eq> Eq for RangeFrom<Idx>
impl<Idx: Eq> Eq for RangeInclusive<Idx>
impl<Idx: Eq> Eq for RangeTo<Idx>
impl<Idx: Eq> Eq for RangeToInclusive<Idx>
impl<P: Deref<Target: Eq>> Eq for Pin<P>
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
impl<T> Eq for Discriminant<T>
impl<T, const LANES: usize> Eq for Simd<T, LANES> where
LaneCount<LANES>: SupportedLaneCount,
T: SimdElement + Eq,
impl<T: Eq + Copy> Eq for Cell<T>
impl<T: Eq + ?Sized> Eq for ManuallyDrop<T>
impl<T: Eq> Eq for Bound<T>
impl<T: Eq> Eq for Option<T>
impl<T: Eq> Eq for Poll<T>
impl<T: Eq> Eq for [T]
impl<T: Eq> Eq for (T₁, T₂, …, Tₙ) where
T: ?Sized,
This trait is implemented for tuples up to twelve items long.