pub trait Eq: PartialEq<Self> + PointeeSized { }Expand description
Trait for comparisons corresponding to equivalence relations.
The primary difference to PartialEq is the additional requirement for reflexivity. A type
that implements PartialEq guarantees that for all a, b and c:
- symmetric:
a == bimpliesb == aanda != bimplies!(a == b) - transitive:
a == bandb == cimpliesa == c
Eq, which builds on top of PartialEq also implies:
- reflexive:
a == a
This property cannot be checked by the compiler, and therefore Eq is a trait without methods.
Violating this property is a logic error. The behavior resulting from a logic error is not
specified, but users of the trait must ensure that such logic errors do not result in
undefined behavior. This means that unsafe code must not rely on the correctness of these
methods.
Floating point types such as f32 and f64 implement only PartialEq but not Eq
because NaN != NaN.
§Derivable
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.
§How can I implement Eq?
If you cannot use the derive strategy, specify that your type implements Eq, which has no
extra methods:
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl Eq for AsciiChar
ferrocene_certified only.impl Eq for Infallible
impl Eq for FromBytesWithNulError
ferrocene_certified only.impl Eq for core::fmt::Alignment
impl Eq for DebugAsHex
impl Eq for Sign
impl Eq for AtomicOrdering
impl Eq for IpAddr
ferrocene_certified only.impl Eq for Ipv6MulticastScope
ferrocene_certified only.impl Eq for SocketAddr
ferrocene_certified only.impl Eq for FpCategory
impl Eq for IntErrorKind
impl Eq for GetDisjointMutError
impl Eq for SearchStep
ferrocene_certified only.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
ferrocene_certified only.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
impl Eq for ByteStr
ferrocene_certified only.impl Eq for CharTryFromError
ferrocene_certified only.impl Eq for DecodeUtf16Error
ferrocene_certified only.impl Eq for ParseCharError
ferrocene_certified only.impl Eq for TryFromCharError
ferrocene_certified only.impl Eq for CStr
ferrocene_certified only.impl Eq for FromBytesUntilNulError
ferrocene_certified only.impl Eq for Error
impl Eq for FormattingOptions
impl Eq for PhantomPinned
impl Eq for Assume
ferrocene_certified only.impl Eq for AddrParseError
ferrocene_certified only.impl Eq for Ipv4Addr
ferrocene_certified only.impl Eq for Ipv6Addr
ferrocene_certified only.impl Eq for SocketAddrV4
ferrocene_certified only.impl Eq for SocketAddrV6
ferrocene_certified only.impl Eq for ParseFloatError
ferrocene_certified only.impl Eq for ParseIntError
impl Eq for TryFromIntError
impl Eq for RangeFull
impl Eq for Location<'_>
ferrocene_certified only.impl Eq for core::ptr::Alignment
impl Eq for ParseBoolError
impl Eq for Utf8Error
impl Eq for Duration
impl Eq for TryFromFloatSecsError
impl<'a> Eq for Utf8Pattern<'a>
ferrocene_certified only.impl<'a> Eq for PhantomContravariantLifetime<'a>
ferrocene_certified only.impl<'a> Eq for PhantomCovariantLifetime<'a>
ferrocene_certified only.impl<'a> Eq for PhantomInvariantLifetime<'a>
ferrocene_certified only.impl<'a> Eq for Utf8Chunk<'a>
ferrocene_certified only.impl<A> Eq for &Awhere
A: Eq + PointeeSized,
impl<A> Eq for &mut Awhere
A: Eq + PointeeSized,
impl<B: Eq, C: Eq> Eq for ControlFlow<B, C>
impl<Dyn: PointeeSized> Eq for DynMetadata<Dyn>
ferrocene_certified only.impl<F: FnPtr> Eq for F
ferrocene_certified only.impl<H> Eq for BuildHasherDefault<H>
ferrocene_certified only.impl<Idx: Eq> Eq for core::ops::Range<Idx>
impl<Idx: Eq> Eq for core::ops::RangeFrom<Idx>
impl<Idx: Eq> Eq for core::ops::RangeInclusive<Idx>
impl<Idx: Eq> Eq for RangeTo<Idx>
impl<Idx: Eq> Eq for core::ops::RangeToInclusive<Idx>
impl<Idx: Eq> Eq for core::range::Range<Idx>
ferrocene_certified only.impl<Idx: Eq> Eq for core::range::RangeFrom<Idx>
ferrocene_certified only.impl<Idx: Eq> Eq for core::range::RangeInclusive<Idx>
ferrocene_certified only.impl<Idx: Eq> Eq for core::range::RangeToInclusive<Idx>
ferrocene_certified only.impl<Ptr: Deref<Target: Eq>> Eq for Pin<Ptr>
ferrocene_certified only.impl<T> Eq for PhantomContravariant<T>where
T: ?Sized,
ferrocene_certified only.impl<T> Eq for PhantomCovariant<T>where
T: ?Sized,
ferrocene_certified only.impl<T> Eq for PhantomInvariant<T>where
T: ?Sized,
ferrocene_certified only.impl<T> Eq for Discriminant<T>
ferrocene_certified only.impl<T> Eq for NonZero<T>where
T: ZeroablePrimitive + Eq,
ferrocene_certified only.impl<T> Eq for Exclusive<T>
ferrocene_certified only.impl<T, const N: usize> Eq for Simd<T, N>
ferrocene_certified only.impl<T: PointeeSized> Eq for *const T
Pointer equality is an equivalence relation.
impl<T: PointeeSized> Eq for *mut T
Pointer equality is an equivalence relation.
impl<T: PointeeSized> Eq for PhantomData<T>
ferrocene_certified only.impl<T: PointeeSized> Eq for NonNull<T>
ferrocene_certified only.impl<T: Eq + Copy> Eq for Cell<T>
ferrocene_certified only.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>
ferrocene_certified only.impl<T: Eq> Eq for [T]
impl<T: Eq> Eq for (T₁, T₂, …, Tₙ)
ferrocene_certified only.This trait is implemented for tuples up to twelve items long.
impl<T: Eq> Eq for OnceCell<T>
ferrocene_certified only.impl<T: Eq> Eq for Saturating<T>
ferrocene_certified only.impl<T: Eq> Eq for Wrapping<T>
ferrocene_certified only.impl<T: Eq> Eq for Reverse<T>
impl<T: Eq, E: Eq> Eq for Result<T, E>
impl<T: Eq, const N: usize> Eq for [T; N]
impl<T: ?Sized + Eq> Eq for RefCell<T>
ferrocene_certified only.impl<Y: Eq, R: Eq> Eq for CoroutineState<Y, R>
ferrocene_certified only.