Skip to main content

Eq

Trait Eq 

1.0.0 (const: unstable) · Source
pub trait Eq: PartialEq {
    // Provided methods
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) { ... }
#[doc(hidden)]
fn assert_fields_are_eq(&self) { ... } }
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 implies b == a
  • transitive: a == b and b == c implies a == c
  • consistent: a != b if and only if !(a == b)

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:

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 {}

Provided Methods§

1.0.0 (const: unstable) · Source

#[doc(hidden)]
fn assert_receiver_is_total_eq(&self)

👎Deprecated since 1.95.0:

implementation detail of #[derive(Eq)]

Source

#[doc(hidden)]
fn assert_fields_are_eq(&self)

🔬This is a nightly-only experimental API. (derive_eq_internals)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Eq for !

1.0.0 (const: unstable) · Source§

impl Eq for ()

1.26.0 · Source§

impl Eq for AccessError

1.0.0 · Source§

impl Eq for AddrParseError

Source§

impl Eq for std::mem::Alignment

1.28.0 · Source§

impl Eq for std::fmt::Alignment

Source§

impl Eq for AllocError

Source§

impl Eq for AsciiChar

Source§

impl Eq for Assume

Source§

impl Eq for AtomicOrdering

1.65.0 · Source§

impl Eq for BacktraceStatus

Source§

impl Eq for BacktraceStyle

Source§

impl Eq for Big8x3

Source§

impl Eq for Big32x40

Source§

impl Eq for ByteStr

Source§

impl Eq for ByteString

1.64.0 · Source§

impl Eq for CStr

1.64.0 · Source§

impl Eq for CString

Source§

impl Eq for CharCase

1.34.0 · Source§

impl Eq for CharTryFromError

Source§

impl Eq for CodePoint

Source§

impl Eq for CodePointInner

1.0.0 · Source§

impl Eq for Components<'_>

1.27.0 · Source§

impl Eq for CpuidResult

Source§

impl Eq for DebugAsHex

Source§

impl Eq for Decimal

1.9.0 · Source§

impl Eq for DecodeUtf16Error

Source§

impl Eq for Decoded

1.3.0 · Source§

impl Eq for Duration

1.0.0 · Source§

impl Eq for Error

1.0.0 · Source§

impl Eq for ErrorKind

Source§

impl Eq for ExitCode

1.0.0 · Source§

impl Eq for std::process::ExitStatus

Source§

impl Eq for std::sys::process::unix::unix::ExitStatus

Source§

impl Eq for std::process::ExitStatusError

Source§

impl Eq for std::sys::process::unix::unix::ExitStatusError

Source§

impl Eq for FieldId

Source§

impl Eq for FilePermissions

1.1.0 · Source§

impl Eq for std::fs::FileType

Source§

impl Eq for std::sys::fs::unix::FileType

Source§

impl Eq for FormattingOptions

1.0.0 · Source§

impl Eq for FpCategory

1.69.0 · Source§

impl Eq for FromBytesUntilNulError

1.64.0 · Source§

impl Eq for FromBytesWithNulError

1.0.0 · Source§

impl Eq for FromUtf8Error

1.64.0 · Source§

impl Eq for FromVecWithNulError

Source§

impl Eq for FullDecoded

1.86.0 · Source§

impl Eq for GetDisjointMutError

Source§

impl Eq for I32NotAllOnes

Source§

impl Eq for I64NotAllOnes

1.34.0 (const: unstable) · Source§

impl Eq for Infallible

1.8.0 · Source§

impl Eq for std::time::Instant

Source§

impl Eq for std::sys::time::unix::Instant

1.55.0 · Source§

impl Eq for IntErrorKind

1.64.0 · Source§

impl Eq for IntoStringError

1.7.0 · Source§

impl Eq for IpAddr

1.0.0 (const: unstable) · Source§

impl Eq for Ipv4Addr

1.0.0 (const: unstable) · Source§

impl Eq for Ipv6Addr

Source§

impl Eq for Ipv6MulticastScope

1.28.0 · Source§

impl Eq for Layout

1.50.0 · Source§

impl Eq for LayoutError

Source§

impl Eq for Locality

1.10.0 · Source§

impl Eq for Location<'_>

Source§

impl Eq for MapsEntry

Source§

impl Eq for Nanoseconds

Source§

impl Eq for NonZeroCharInner

Source§

impl Eq for NonZeroI8Inner

Source§

impl Eq for NonZeroI16Inner

Source§

impl Eq for NonZeroI32Inner

Source§

impl Eq for NonZeroI64Inner

Source§

impl Eq for NonZeroI128Inner

Source§

impl Eq for NonZeroIsizeInner

Source§

impl Eq for NonZeroU8Inner

Source§

impl Eq for NonZeroU16Inner

Source§

impl Eq for NonZeroU32Inner

Source§

impl Eq for NonZeroU64Inner

Source§

impl Eq for NonZeroU128Inner

Source§

impl Eq for NonZeroUsizeInner

1.64.0 · Source§

impl Eq for NulError

Source§

impl Eq for Operation

1.0.0 (const: unstable) · Source§

impl Eq for std::cmp::Ordering

1.0.0 · Source§

impl Eq for std::sync::atomic::Ordering

1.0.0 · Source§

impl Eq for OsStr

1.0.0 · Source§

impl Eq for OsString

1.0.0 · Source§

impl Eq for Output

1.0.0 · Source§

impl Eq for ParseBoolError

1.20.0 · Source§

impl Eq for ParseCharError

1.0.0 · Source§

impl Eq for ParseFloatError

1.0.0 · Source§

impl Eq for ParseIntError

1.0.0 · Source§

impl Eq for Path

1.0.0 · Source§

impl Eq for PathBuf

1.0.0 · Source§

impl Eq for Permissions

1.33.0 · Source§

impl Eq for PhantomPinned

Source§

impl Eq for PrintFmt

Source§

impl Eq for ProgramKind

1.0.0 (const: unstable) · Source§

impl Eq for RangeFull

1.0.0 · Source§

impl Eq for RecvError

1.12.0 · Source§

impl Eq for RecvTimeoutError

Source§

impl Eq for SearchStep

1.0.0 · Source§

impl Eq for SeekFrom

Source§

impl Eq for Selected

1.0.0 · Source§

impl Eq for Shutdown

Source§

impl Eq for core::num::imp::flt2dec::Sign

Source§

impl Eq for std::fmt::Sign

Source§

impl Eq for SimdAlign

1.0.0 · Source§

impl Eq for SocketAddr

1.0.0 · Source§

impl Eq for SocketAddrV4

1.0.0 · Source§

impl Eq for SocketAddrV6

1.0.0 · Source§

impl Eq for String

1.7.0 · Source§

impl Eq for StripPrefixError

1.8.0 · Source§

impl Eq for std::time::SystemTime

Source§

impl Eq for std::sys::time::unix::SystemTime

1.19.0 · Source§

impl Eq for ThreadId

Source§

impl Eq for Timespec

1.59.0 · Source§

impl Eq for TryFromCharError

1.66.0 · Source§

impl Eq for TryFromFloatSecsError

1.34.0 · Source§

impl Eq for TryFromIntError

1.0.0 · Source§

impl Eq for TryRecvError

1.57.0 · Source§

impl Eq for TryReserveError

Source§

impl Eq for TryReserveErrorKind

1.0.0 (const: unstable) · Source§

impl Eq for TypeId

Source§

impl Eq for U32NotAllOnes

Source§

impl Eq for U64NotAllOnes

Source§

impl Eq for UCred

Available on Android or Apple or Cygwin or DragonFly BSD or FreeBSD or Linux or NetBSD or OpenBSD or QNX SDP 7.x or QNX SDP 8.0+ only.
Source§

impl Eq for UnorderedKeyError

Source§

impl Eq for UsizeNoHighBit

1.0.0 · Source§

impl Eq for Utf8Error

1.0.0 · Source§

impl Eq for VarError

1.5.0 · Source§

impl Eq for WaitTimeoutResult

Source§

impl Eq for Wtf8

Source§

impl Eq for Wtf8Buf

1.0.0 (const: unstable) · Source§

impl Eq for bool

1.0.0 (const: unstable) · Source§

impl Eq for char

1.0.0 (const: unstable) · Source§

impl Eq for i8

1.0.0 (const: unstable) · Source§

impl Eq for i16

1.0.0 (const: unstable) · Source§

impl Eq for i32

1.0.0 (const: unstable) · Source§

impl Eq for i64

1.0.0 (const: unstable) · Source§

impl Eq for i128

1.0.0 (const: unstable) · Source§

impl Eq for isize

1.0.0 (const: unstable) · Source§

impl Eq for str

1.0.0 (const: unstable) · Source§

impl Eq for u8

1.0.0 (const: unstable) · Source§

impl Eq for u16

1.0.0 (const: unstable) · Source§

impl Eq for u32

1.0.0 (const: unstable) · Source§

impl Eq for u64

1.0.0 (const: unstable) · Source§

impl Eq for u128

1.0.0 (const: unstable) · Source§

impl Eq for usize

1.0.0 · Source§

impl<'a> Eq for Component<'a>

Source§

impl<'a> Eq for Part<'a>

Source§

impl<'a> Eq for PhantomContravariantLifetime<'a>

Source§

impl<'a> Eq for PhantomCovariantLifetime<'a>

Source§

impl<'a> Eq for PhantomInvariantLifetime<'a>

1.0.0 · Source§

impl<'a> Eq for Prefix<'a>

1.0.0 · Source§

impl<'a> Eq for PrefixComponent<'a>

1.79.0 · Source§

impl<'a> Eq for Utf8Chunk<'a>

Source§

impl<'a> Eq for Utf8Pattern<'a>

1.0.0 (const: unstable) · Source§

impl<A, Z, Y, X, W, V, U, T> Eq for (A, Z, Y, X, W, V, U, T)
where A: Eq, Z: Eq, Y: Eq, X: Eq, W: Eq, V: Eq, U: Eq, T: Eq,

1.0.0 (const: unstable) · Source§

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

1.0.0 (const: unstable) · Source§

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

1.0.0 (const: unstable) · Source§

impl<B, A, Z, Y, X, W, V, U, T> Eq for (B, A, Z, Y, X, W, V, U, T)
where B: Eq, A: Eq, Z: Eq, Y: Eq, X: Eq, W: Eq, V: Eq, U: Eq, T: Eq,

1.55.0 (const: unstable) · Source§

impl<B, C> Eq for ControlFlow<B, C>
where B: Eq, C: Eq,

1.0.0 · Source§

impl<B> Eq for Cow<'_, B>
where B: Eq + ToOwned + ?Sized,

1.0.0 (const: unstable) · Source§

impl<C, B, A, Z, Y, X, W, V, U, T> Eq for (C, B, A, Z, Y, X, W, V, U, T)
where C: Eq, B: Eq, A: Eq, Z: Eq, Y: Eq, X: Eq, W: Eq, V: Eq, U: Eq, T: Eq,

1.0.0 (const: unstable) · Source§

impl<D, C, B, A, Z, Y, X, W, V, U, T> Eq for (D, C, B, A, Z, Y, X, W, V, U, T)
where D: Eq, C: Eq, B: Eq, A: Eq, Z: Eq, Y: Eq, X: Eq, W: Eq, V: Eq, U: Eq, T: Eq,

Source§

impl<Dyn> Eq for DynMetadata<Dyn>
where Dyn: ?Sized,

1.0.0 (const: unstable) · Source§

impl<E, D, C, B, A, Z, Y, X, W, V, U, T> Eq for (E, D, C, B, A, Z, Y, X, W, V, U, T)
where E: Eq, D: Eq, C: Eq, B: Eq, A: Eq, Z: Eq, Y: Eq, X: Eq, W: Eq, V: Eq, U: Eq, T: Eq,

1.4.0 · Source§

impl<F> Eq for F
where F: FnPtr,

1.29.0 · Source§

impl<H> Eq for BuildHasherDefault<H>

1.0.0 · Source§

impl<Idx> Eq for std::ops::Range<Idx>
where Idx: Eq,

1.96.0 (const: unstable) · Source§

impl<Idx> Eq for std::range::Range<Idx>
where Idx: Eq,

1.0.0 · Source§

impl<Idx> Eq for std::ops::RangeFrom<Idx>
where Idx: Eq,

1.96.0 (const: unstable) · Source§

impl<Idx> Eq for std::range::RangeFrom<Idx>
where Idx: Eq,

1.26.0 (const: unstable) · Source§

impl<Idx> Eq for std::ops::RangeInclusive<Idx>
where Idx: Eq,

1.95.0 · Source§

impl<Idx> Eq for std::range::RangeInclusive<Idx>
where Idx: Eq,

1.0.0 · Source§

impl<Idx> Eq for RangeTo<Idx>
where Idx: Eq,

1.26.0 · Source§

impl<Idx> Eq for std::ops::RangeToInclusive<Idx>
where Idx: Eq,

1.96.0 · Source§

impl<Idx> Eq for std::range::RangeToInclusive<Idx>
where Idx: Eq,

1.0.0 · Source§

impl<K, V, A> Eq for BTreeMap<K, V, A>
where K: Eq, V: Eq, A: Allocator + Clone,

1.0.0 · Source§

impl<K, V, S, A> Eq for HashMap<K, V, S, A>
where K: Eq + Hash, V: Eq, S: BuildHasher, A: Allocator,

1.41.0 · Source§

impl<Ptr> Eq for Pin<Ptr>
where Ptr: Deref, <Ptr as Deref>::Target: Eq,

1.0.0 · Source§

impl<T, A> Eq for Arc<T, A>
where T: Eq + ?Sized, A: Allocator,

1.0.0 · Source§

impl<T, A> Eq for BTreeSet<T, A>
where T: Eq, A: Allocator + Clone,

1.0.0 · Source§

impl<T, A> Eq for Box<T, A>
where T: Eq + ?Sized, A: Allocator,

1.0.0 · Source§

impl<T, A> Eq for LinkedList<T, A>
where T: Eq, A: Allocator,

1.0.0 · Source§

impl<T, A> Eq for Rc<T, A>
where T: Eq + ?Sized, A: Allocator,

Source§

impl<T, A> Eq for UniqueArc<T, A>
where T: Eq + ?Sized, A: Allocator,

Source§

impl<T, A> Eq for UniqueRc<T, A>
where T: Eq + ?Sized, A: Allocator,

1.0.0 · Source§

impl<T, A> Eq for Vec<T, A>
where T: Eq, A: Allocator,

1.0.0 · Source§

impl<T, A> Eq for VecDeque<T, A>
where T: Eq, A: Allocator,

1.0.0 (const: unstable) · Source§

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

1.0.0 · Source§

impl<T, S, A> Eq for HashSet<T, S, A>
where T: Eq + Hash, S: BuildHasher, A: Allocator,

Source§

impl<T, const N: usize> Eq for Simd<T, N>
where T: SimdElement + Eq,

1.0.0 (const: unstable) · Source§

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

Source§

impl<T, const VARIANT: u32, const FIELD: u32> Eq for FieldRepresentingType<T, VARIANT, FIELD>
where T: ?Sized,

Source§

impl<T: Eq> Eq for CachePadded<T>

1.70.0 · Source§

impl<T: Eq> Eq for OnceLock<T>

1.0.0 · Source§

impl<T: Eq> Eq for SendError<T>

Source§

impl<T: Eq> Eq for SendTimeoutError<T>

1.0.0 · Source§

impl<T: Eq> Eq for TrySendError<T>

1.0.0 (const: unstable) · Source§

impl<T> Eq for (T₁, T₂, …, Tₙ)
where T: Eq,

This trait is implemented for tuples up to twelve items long.

1.0.0 · Source§

impl<T> Eq for *const T
where T: ?Sized,

Pointer equality is an equivalence relation.

1.0.0 · Source§

impl<T> Eq for *mut T
where T: ?Sized,

Pointer equality is an equivalence relation.

1.17.0 (const: unstable) · Source§

impl<T> Eq for Bound<T>
where T: Eq,

1.2.0 · Source§

impl<T> Eq for Cell<T>
where T: Eq + Copy,

1.0.0 · Source§

impl<T> Eq for Cursor<T>
where T: Eq,

1.21.0 · Source§

impl<T> Eq for Discriminant<T>

1.20.0 · Source§

impl<T> Eq for ManuallyDrop<T>
where T: Eq + ?Sized,

1.25.0 · Source§

impl<T> Eq for NonNull<T>
where T: ?Sized,

1.28.0 (const: unstable) · Source§

impl<T> Eq for NonZero<T>
where T: ZeroablePrimitive + Eq,

1.70.0 · Source§

impl<T> Eq for OnceCell<T>
where T: Eq,

1.0.0 (const: unstable) · Source§

impl<T> Eq for Option<T>
where T: Eq,

Source§

impl<T> Eq for PhantomContravariant<T>
where T: ?Sized,

Source§

impl<T> Eq for PhantomCovariant<T>
where T: ?Sized,

1.0.0 · Source§

impl<T> Eq for PhantomData<T>
where T: ?Sized,

Source§

impl<T> Eq for PhantomInvariant<T>
where T: ?Sized,

1.36.0 · Source§

impl<T> Eq for Poll<T>
where T: Eq,

1.2.0 · Source§

impl<T> Eq for RefCell<T>
where T: Eq + ?Sized,

1.19.0 (const: unstable) · Source§

impl<T> Eq for Reverse<T>
where T: Eq,

1.74.0 · Source§

impl<T> Eq for Saturating<T>
where T: Eq,

Source§

impl<T> Eq for SyncView<T>
where T: Sync + Eq + ?Sized,

Source§

impl<T> Eq for TraitImpl<T>
where T: Eq + ?Sized,

1.0.0 · Source§

impl<T> Eq for Wrapping<T>
where T: Eq,

1.0.0 (const: unstable) · Source§

impl<T> Eq for [T]
where T: Eq,

1.0.0 (const: unstable) · Source§

impl<U, T> Eq for (U, T)
where U: Eq, T: Eq,

1.0.0 (const: unstable) · Source§

impl<V, U, T> Eq for (V, U, T)
where V: Eq, U: Eq, T: Eq,

1.0.0 (const: unstable) · Source§

impl<W, V, U, T> Eq for (W, V, U, T)
where W: Eq, V: Eq, U: Eq, T: Eq,

1.0.0 (const: unstable) · Source§

impl<X, W, V, U, T> Eq for (X, W, V, U, T)
where X: Eq, W: Eq, V: Eq, U: Eq, T: Eq,

Source§

impl<Y, R> Eq for CoroutineState<Y, R>
where Y: Eq, R: Eq,

1.0.0 (const: unstable) · Source§

impl<Y, X, W, V, U, T> Eq for (Y, X, W, V, U, T)
where Y: Eq, X: Eq, W: Eq, V: Eq, U: Eq, T: Eq,

1.0.0 (const: unstable) · Source§

impl<Z, Y, X, W, V, U, T> Eq for (Z, Y, X, W, V, U, T)
where Z: Eq, Y: Eq, X: Eq, W: Eq, V: Eq, U: Eq, T: Eq,