pub trait Eq: PartialEq { }
Expand description
Trait for comparisons corresponding to equivalence relations.
This means, that in addition to a == b
and a != b
being strict inverses,
the relation must be (for all a
, b
and c
):
- reflexive:
a == a
; - symmetric:
a == b
impliesb == a
(required byPartialEq
as well); and - transitive:
a == b
andb == c
impliesa == c
(required byPartialEq
as well).
This property cannot be checked by the compiler, and therefore Eq
implies
PartialEq
, and has no extra 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.
Implement Eq
in addition to PartialEq
if it’s guaranteed that
PartialEq::eq(a, a)
always returns true
(reflexivity), in addition to
the symmetric and transitive properties already required by PartialEq
.
§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 {}
Object Safety§
Implementors§
impl Eq for ConversionError
impl Eq for gstd::errors::CoreError
impl Eq for gstd::errors::Error
impl Eq for ErrorReplyReason
impl Eq for ExecutionError
impl Eq for ExtError
impl Eq for MemoryError
impl Eq for MessageError
impl Eq for ReplyCode
impl Eq for ReservationError
impl Eq for SignalCode
impl Eq for SimpleExecutionError
impl Eq for SimpleProgramCreationError
impl Eq for SuccessReplyReason
impl Eq for UsageError
impl Eq for AsciiChar
impl Eq for TryReserveErrorKind
impl Eq for gstd::prelude::collections::hashbrown::TryReserveError
impl Eq for Infallible
impl Eq for gstd::prelude::fmt::Alignment
impl Eq for FpCategory
impl Eq for IntErrorKind
impl Eq for SearchStep
impl Eq for gstd::prelude::cmp::Ordering
impl Eq for IpAddr
impl Eq for Ipv6MulticastScope
impl Eq for SocketAddr
impl Eq for core::sync::atomic::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 gstd::errors::CodecError
impl Eq for ErrorReplyPayload
impl Eq for SyscallError
impl Eq for gstd::msg::MessageHandle
impl Eq for ActorId
impl Eq for CodeId
impl Eq for MessageId
impl Eq for Percent
impl Eq for ReservationId
impl Eq for MetaType
impl Eq for TypeId
impl Eq for CharTryFromError
impl Eq for DecodeUtf16Error
impl Eq for ParseCharError
impl Eq for TryFromCharError
impl Eq for UnorderedKeyError
impl Eq for gstd::prelude::collections::TryReserveError
impl Eq for CStr
impl Eq for CString
impl Eq for FromBytesUntilNulError
impl Eq for FromBytesWithNulError
impl Eq for FromVecWithNulError
impl Eq for IntoStringError
impl Eq for NulError
impl Eq for gstd::prelude::fmt::Error
impl Eq for PhantomPinned
impl Eq for Assume
impl Eq for ParseFloatError
impl Eq for ParseIntError
impl Eq for TryFromIntError
impl Eq for RangeFull
impl Eq for gstd::prelude::ptr::Alignment
impl Eq for ParseBoolError
impl Eq for Utf8Error
impl Eq for FromUtf8Error
impl Eq for String
impl Eq for Duration
impl Eq for TryFromFloatSecsError
impl Eq for Layout
impl Eq for LayoutError
impl Eq for core::alloc::AllocError
impl Eq for CpuidResult
impl Eq for Ipv4Addr
impl Eq for Ipv6Addr
impl Eq for AddrParseError
impl Eq for SocketAddrV4
impl Eq for SocketAddrV6
impl Eq for ATerm
impl Eq for B0
impl Eq for B1
impl Eq for Z0
impl Eq for Equal
impl Eq for Greater
impl Eq for Less
impl Eq for UTerm
impl Eq for Aborted
impl Eq for AllocError
impl Eq for BigEndian
impl Eq for Canceled
impl Eq for Error
impl Eq for Error
impl Eq for Error
impl Eq for Error
impl Eq for Error
impl Eq for Error
impl Eq for Error
impl Eq for FromStrRadixErrKind
impl Eq for H128
impl Eq for H160
impl Eq for H256
impl Eq for H384
impl Eq for H512
impl Eq for H768
impl Eq for InvalidBufferSize
impl Eq for InvalidLength
impl Eq for LittleEndian
impl Eq for MacError
impl Eq for MessageHandle
impl Eq for MetaForm
impl Eq for NonZeroU256
impl Eq for OptionBool
impl Eq for PathError
impl Eq for PollNext
impl Eq for PortableForm
impl Eq for PortableRegistry
impl Eq for PortableType
impl Eq for Registry
impl Eq for TypeDefPrimitive
impl Eq for U128
impl Eq for U256
impl Eq for U512
impl<'a> Eq for Location<'a>
impl<'a> Eq for Utf8Chunk<'a>
impl<'a, T> Eq for CompactRef<'a, T>where
T: Eq,
impl<'a, T> Eq for Symbol<'a, T>where
T: Eq + 'a,
impl<A> Eq for &A
impl<A> Eq for &mut A
impl<B> Eq for Cow<'_, B>
impl<B, C> Eq for ControlFlow<B, C>
impl<Dyn> Eq for DynMetadata<Dyn>where
Dyn: ?Sized,
impl<F> Eq for Fwhere
F: FnPtr,
impl<H> Eq for BuildHasherDefault<H>
impl<Idx> Eq for gstd::prelude::ops::Range<Idx>where
Idx: Eq,
impl<Idx> Eq for gstd::prelude::ops::RangeFrom<Idx>where
Idx: Eq,
impl<Idx> Eq for gstd::prelude::ops::RangeInclusive<Idx>where
Idx: Eq,
impl<Idx> Eq for RangeTo<Idx>where
Idx: Eq,
impl<Idx> Eq for RangeToInclusive<Idx>where
Idx: Eq,
impl<Idx> Eq for core::range::Range<Idx>where
Idx: Eq,
impl<Idx> Eq for core::range::RangeFrom<Idx>where
Idx: Eq,
impl<Idx> Eq for core::range::RangeInclusive<Idx>where
Idx: Eq,
impl<K, V, A> Eq for BTreeMap<K, V, A>
impl<K, V, S, A> Eq for HashMap<K, V, S, A>
impl<Ptr> Eq for Pin<Ptr>
impl<T> Eq for Option<T>where
T: Eq,
impl<T> Eq for Bound<T>where
T: Eq,
impl<T> Eq for Poll<T>where
T: Eq,
impl<T> Eq for *const Twhere
T: ?Sized,
impl<T> Eq for *mut Twhere
T: ?Sized,
impl<T> Eq for [T]where
T: Eq,
impl<T> Eq for (T₁, T₂, …, Tₙ)
This trait is implemented for tuples up to twelve items long.