pub trait Eq: PartialEq { }
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 == b
impliesb == a
anda != b
implies!(a == b)
- transitive:
a == b
andb == c
impliesa == 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 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
extra 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 {}
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 wiwi::prelude_std::atomic::Ordering
impl Eq for wiwi::prelude_std::cmp::Ordering
impl Eq for Infallible
impl Eq for VarError
impl Eq for wiwi::prelude_std::fmt::Alignment
impl Eq for alloc::collections::TryReserveErrorKind
impl Eq for AsciiChar
impl Eq for IpAddr
impl Eq for Ipv6MulticastScope
impl Eq for SocketAddr
impl Eq for FpCategory
impl Eq for IntErrorKind
impl Eq for BacktraceStatus
impl Eq for SeekFrom
impl Eq for ErrorKind
impl Eq for Shutdown
impl Eq for RecvTimeoutError
impl Eq for std::sync::mpsc::TryRecvError
impl Eq for Colons
impl Eq for Fixed
impl Eq for Numeric
impl Eq for OffsetPrecision
impl Eq for Pad
impl Eq for ParseErrorKind
impl Eq for SecondsFormat
impl Eq for Month
impl Eq for RoundingError
impl Eq for Weekday
impl Eq for BacktraceStyle
impl Eq for SearchStep
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 wiwi::prelude_std::alloc_mod::AllocError
impl Eq for Layout
impl Eq for LayoutError
impl Eq for Error
impl Eq for UnorderedKeyError
impl Eq for alloc::collections::TryReserveError
impl Eq for CString
impl Eq for FromVecWithNulError
impl Eq for IntoStringError
impl Eq for NulError
impl Eq for CharTryFromError
impl Eq for ParseCharError
impl Eq for DecodeUtf16Error
impl Eq for TryFromCharError
impl Eq for CpuidResult
impl Eq for CStr
impl Eq for FromBytesUntilNulError
impl Eq for FromBytesWithNulError
impl Eq for Ipv4Addr
impl Eq for Ipv6Addr
impl Eq for AddrParseError
impl Eq for SocketAddrV4
impl Eq for SocketAddrV6
impl Eq for ParseFloatError
impl Eq for ParseIntError
impl Eq for TryFromIntError
impl Eq for Duration
impl Eq for TryFromFloatSecsError
impl Eq for OsStr
impl Eq for OsString
impl Eq for FileType
impl Eq for Permissions
impl Eq for std::os::unix::net::ucred::UCred
impl Eq for Components<'_>
impl Eq for Path
impl Eq for PathBuf
impl Eq for StripPrefixError
impl Eq for ExitStatus
impl Eq for ExitStatusError
impl Eq for Output
impl Eq for std::sync::condvar::WaitTimeoutResult
impl Eq for std::sync::mpsc::RecvError
impl Eq for AccessError
impl Eq for ThreadId
impl Eq for std::time::Instant
impl Eq for SystemTime
impl Eq for Parsed
impl Eq for InternalFixed
impl Eq for InternalNumeric
impl Eq for OffsetFormat
impl Eq for ParseError
impl Eq for Months
impl Eq for ParseMonthError
impl Eq for NaiveDate
impl Eq for NaiveDateDaysIterator
impl Eq for NaiveDateWeeksIterator
impl Eq for NaiveDateTime
impl Eq for IsoWeek
impl Eq for Days
impl Eq for NaiveTime
impl Eq for FixedOffset
impl Eq for Utc
impl Eq for OutOfRange
impl Eq for OutOfRangeError
impl Eq for TimeDelta
impl Eq for ParseWeekdayError
impl Eq for Assume
impl Eq for RangeFull
impl Eq for wiwi::prelude_std::ptr::Alignment
impl Eq for ParseBoolError
impl Eq for Utf8Error
impl Eq for FromUtf8Error
impl Eq for PhantomPinned
impl Eq for String
impl Eq for TypeId
impl Eq for AllocError
impl Eq for Bytes
impl Eq for BytesMut
impl Eq for Domain
impl Eq for Elapsed
impl Eq for FilterOp
impl Eq for Id
impl Eq for Instant
impl Eq for Interest
impl Eq for Interest
impl Eq for MissedTickBehavior
impl Eq for OnceState
impl Eq for ParkResult
impl Eq for ParkToken
impl Eq for Protocol
impl Eq for Ready
impl Eq for RecvError
impl Eq for RecvError
impl Eq for RecvFlags
impl Eq for RequeueOp
impl Eq for RuntimeFlavor
impl Eq for SigId
impl Eq for SignalKind
impl Eq for SockAddr
impl Eq for Token
impl Eq for TryAcquireError
impl Eq for TryRecvError
impl Eq for TryRecvError
impl Eq for TryRecvError
impl Eq for TryReserveError
impl Eq for TryReserveError
impl Eq for TryReserveErrorKind
impl Eq for Type
impl Eq for UCred
impl Eq for UnparkResult
impl Eq for UnparkToken
impl Eq for WaitTimeoutResult
impl<'a> Eq for Component<'a>
impl<'a> Eq for Prefix<'a>
impl<'a> Eq for Item<'a>
impl<'a> Eq for Utf8Pattern<'a>
impl<'a> Eq for PrefixComponent<'a>
impl<'a> Eq for Location<'a>
impl<'a> Eq for Utf8Chunk<'a>
impl<A> Eq for &A
impl<A> Eq for &mut A
impl<A> Eq for SmallVec<A>where
A: Array,
<A as Array>::Item: Eq,
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 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<Idx> Eq for wiwi::prelude_std::ops::Range<Idx>where
Idx: Eq,
impl<Idx> Eq for wiwi::prelude_std::ops::RangeFrom<Idx>where
Idx: Eq,
impl<Idx> Eq for wiwi::prelude_std::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<K, V, A> Eq for BTreeMap<K, V, A>
impl<K, V, S> Eq for std::collections::hash::map::HashMap<K, V, S>
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 Poll<T>where
T: Eq,
impl<T> Eq for std::sync::mpmc::error::SendTimeoutError<T>where
T: Eq,
impl<T> Eq for std::sync::mpsc::TrySendError<T>where
T: Eq,
impl<T> Eq for LocalResult<T>where
T: Eq,
impl<T> Eq for Bound<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.