Eq

Trait Eq 

1.6.0 (const: unstable) · Source
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 == b implies b == a and a != b implies !(a == b)
  • transitive: a == b and b == c implies a == 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:

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§

Source§

impl Eq for AsciiChar

Available on non-crate feature ferrocene_certified only.
1.34.0 (const: unstable) · Source§

impl Eq for Infallible

Available on non-crate feature ferrocene_certified only.
1.64.0 · Source§

impl Eq for FromBytesWithNulError

Available on non-crate feature ferrocene_certified only.
1.28.0 · Source§

impl Eq for core::fmt::Alignment

Source§

impl Eq for DebugAsHex

Source§

impl Eq for Sign

Source§

impl Eq for AtomicOrdering

1.7.0 · Source§

impl Eq for IpAddr

Available on non-crate feature ferrocene_certified only.
Source§

impl Eq for Ipv6MulticastScope

Available on non-crate feature ferrocene_certified only.
1.0.0 · Source§

impl Eq for SocketAddr

Available on non-crate feature ferrocene_certified only.
1.0.0 · Source§

impl Eq for FpCategory

1.55.0 · Source§

impl Eq for IntErrorKind

Available on non-crate feature ferrocene_certified only.
1.86.0 · Source§

impl Eq for GetDisjointMutError

Available on non-crate feature ferrocene_certified only.
Source§

impl Eq for SearchStep

Available on non-crate feature ferrocene_certified only.
1.0.0 · Source§

impl Eq for core::sync::atomic::Ordering

1.0.0 (const: unstable) · Source§

impl Eq for core::cmp::Ordering

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

Source§

impl Eq for !

Available on non-crate feature ferrocene_certified only.
1.0.0 (const: unstable) · Source§

impl Eq for str

Available on non-crate feature ferrocene_certified only.
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 ()

1.0.0 (const: unstable) · Source§

impl Eq for usize

Source§

impl Eq for AllocError

1.28.0 · Source§

impl Eq for Layout

1.50.0 · Source§

impl Eq for LayoutError

1.0.0 (const: unstable) · Source§

impl Eq for TypeId

Available on non-crate feature ferrocene_certified only.
1.27.0 · Source§

impl Eq for CpuidResult

Available on x86 or x86-64 only.
Source§

impl Eq for ByteStr

Available on non-crate feature ferrocene_certified only.
1.34.0 · Source§

impl Eq for CharTryFromError

Available on non-crate feature ferrocene_certified only.
1.9.0 · Source§

impl Eq for DecodeUtf16Error

Available on non-crate feature ferrocene_certified only.
1.20.0 · Source§

impl Eq for ParseCharError

Available on non-crate feature ferrocene_certified only.
1.59.0 · Source§

impl Eq for TryFromCharError

Available on non-crate feature ferrocene_certified only.
1.64.0 · Source§

impl Eq for CStr

Available on non-crate feature ferrocene_certified only.
1.69.0 · Source§

impl Eq for FromBytesUntilNulError

Available on non-crate feature ferrocene_certified only.
1.0.0 · Source§

impl Eq for Error

Source§

impl Eq for FormattingOptions

1.33.0 · Source§

impl Eq for PhantomPinned

Source§

impl Eq for Assume

Available on non-crate feature ferrocene_certified only.
1.0.0 · Source§

impl Eq for AddrParseError

Available on non-crate feature ferrocene_certified only.
1.0.0 · Source§

impl Eq for Ipv4Addr

Available on non-crate feature ferrocene_certified only.
1.0.0 · Source§

impl Eq for Ipv6Addr

Available on non-crate feature ferrocene_certified only.
1.0.0 · Source§

impl Eq for SocketAddrV4

Available on non-crate feature ferrocene_certified only.
1.0.0 · Source§

impl Eq for SocketAddrV6

Available on non-crate feature ferrocene_certified only.
1.0.0 · Source§

impl Eq for ParseFloatError

Available on non-crate feature ferrocene_certified only.
1.0.0 · Source§

impl Eq for ParseIntError

Available on non-crate feature ferrocene_certified only.
1.34.0 · Source§

impl Eq for TryFromIntError

Available on non-crate feature ferrocene_certified only.
1.0.0 · Source§

impl Eq for RangeFull

1.10.0 · Source§

impl Eq for Location<'_>

Available on non-crate feature ferrocene_certified only.
Source§

impl Eq for core::ptr::Alignment

1.0.0 · Source§

impl Eq for ParseBoolError

Available on non-crate feature ferrocene_certified only.
1.0.0 · Source§

impl Eq for Utf8Error

Available on non-crate feature ferrocene_certified only.
1.3.0 · Source§

impl Eq for Duration

Available on non-crate feature ferrocene_certified only.
1.66.0 · Source§

impl Eq for TryFromFloatSecsError

Available on non-crate feature ferrocene_certified only.
Source§

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

Available on non-crate feature ferrocene_certified only.
Source§

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

Available on non-crate feature ferrocene_certified only.
Source§

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

Available on non-crate feature ferrocene_certified only.
Source§

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

Available on non-crate feature ferrocene_certified only.
1.79.0 · Source§

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

Available on non-crate feature ferrocene_certified only.
1.0.0 (const: unstable) · Source§

impl<A> Eq for &A
where A: Eq + PointeeSized,

Available on non-crate feature ferrocene_certified only.
1.0.0 (const: unstable) · Source§

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

Available on non-crate feature ferrocene_certified only.
1.55.0 (const: unstable) · Source§

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

Source§

impl<Dyn: PointeeSized> Eq for DynMetadata<Dyn>

Available on non-crate feature ferrocene_certified only.
1.4.0 · Source§

impl<F: FnPtr> Eq for F

Available on non-crate feature ferrocene_certified only.
1.29.0 · Source§

impl<H> Eq for BuildHasherDefault<H>

Available on non-crate feature ferrocene_certified only.
1.0.0 · Source§

impl<Idx: Eq> Eq for core::ops::Range<Idx>

1.0.0 · Source§

impl<Idx: Eq> Eq for core::ops::RangeFrom<Idx>

1.26.0 · Source§

impl<Idx: Eq> Eq for core::ops::RangeInclusive<Idx>

1.0.0 · Source§

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

1.26.0 · Source§

impl<Idx: Eq> Eq for core::ops::RangeToInclusive<Idx>

Source§

impl<Idx: Eq> Eq for core::range::Range<Idx>

Available on non-crate feature ferrocene_certified only.
Source§

impl<Idx: Eq> Eq for core::range::RangeFrom<Idx>

Available on non-crate feature ferrocene_certified only.
Source§

impl<Idx: Eq> Eq for core::range::RangeInclusive<Idx>

Available on non-crate feature ferrocene_certified only.
Source§

impl<Idx: Eq> Eq for core::range::RangeToInclusive<Idx>

Available on non-crate feature ferrocene_certified only.
1.41.0 · Source§

impl<Ptr: Deref<Target: Eq>> Eq for Pin<Ptr>

Available on non-crate feature ferrocene_certified only.
Source§

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

Available on non-crate feature ferrocene_certified only.
Source§

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

Available on non-crate feature ferrocene_certified only.
Source§

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

Available on non-crate feature ferrocene_certified only.
1.21.0 · Source§

impl<T> Eq for Discriminant<T>

Available on non-crate feature ferrocene_certified only.
1.28.0 (const: unstable) · Source§

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

Available on non-crate feature ferrocene_certified only.
Source§

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

Available on non-crate feature ferrocene_certified only.
Source§

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

Available on non-crate feature ferrocene_certified only.
1.0.0 · Source§

impl<T: PointeeSized> Eq for *const T

Pointer equality is an equivalence relation.

1.0.0 · Source§

impl<T: PointeeSized> Eq for *mut T

Available on non-crate feature ferrocene_certified only.

Pointer equality is an equivalence relation.

1.0.0 · Source§

impl<T: PointeeSized> Eq for PhantomData<T>

Available on non-crate feature ferrocene_certified only.
1.25.0 · Source§

impl<T: PointeeSized> Eq for NonNull<T>

Available on non-crate feature ferrocene_certified only.
1.2.0 · Source§

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

Available on non-crate feature ferrocene_certified only.
1.20.0 · Source§

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

Available on non-crate feature ferrocene_certified only.
1.17.0 · Source§

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

1.0.0 (const: unstable) · Source§

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

1.36.0 · Source§

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

Available on non-crate feature ferrocene_certified only.
1.0.0 (const: unstable) · Source§

impl<T: Eq> Eq for [T]

Available on non-crate feature ferrocene_certified only.
1.0.0 (const: unstable) · Source§

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

Available on non-crate feature ferrocene_certified only.

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

1.70.0 · Source§

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

Available on non-crate feature ferrocene_certified only.
1.74.0 · Source§

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

Available on non-crate feature ferrocene_certified only.
1.0.0 · Source§

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

Available on non-crate feature ferrocene_certified only.
1.19.0 (const: unstable) · Source§

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

1.0.0 (const: unstable) · Source§

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

1.0.0 (const: unstable) · Source§

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

Available on non-crate feature ferrocene_certified only.
1.2.0 · Source§

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

Available on non-crate feature ferrocene_certified only.
Source§

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

Available on non-crate feature ferrocene_certified only.