Trait core::cmp::Eq

1.0.0 · source ·
pub trait Eq: PartialEq<Self> { }
Expand description

等价关系 等式比较的 Trait。

这意味着,除了 a == ba != b 是严格的逆之外,相等必须是 (对于所有 abc) :

  • 反射: a == a
  • 对称: a == b 表示 b == a; and
  • 可传递的: a == bb == c 表示 a == c

编译器无法检查此属性,因此 Eq 表示 PartialEq,并且没有其他方法。

Derivable

该 trait 可以与 #[derive] 一起使用。 当 derived' 时,由于 Eq` 没有额外的方法,它只是通知编译器这是一个等价关系,而不是部分等价关系。

请注意,derive 策略要求所有字段均为 Eq,这并不总是需要的。

如何实现 Eq

如果您不能使用 derive 策略,请指定您的类型实现 Eq,它没有方法:

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

Implementors§

source§

impl Eq for AsciiChar

1.34.0 · source§

impl Eq for Infallible

1.28.0 · source§

impl Eq for core::fmt::Alignment

1.7.0 · source§

impl Eq for IpAddr

source§

impl Eq for Ipv6MulticastScope

source§

impl Eq for SocketAddr

source§

impl Eq for FpCategory

1.55.0 · source§

impl Eq for IntErrorKind

source§

impl Eq for Which

source§

impl Eq for SearchStep

source§

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

source§

impl Eq for core::cmp::Ordering

source§

impl Eq for bool

source§

impl Eq for char

source§

impl Eq for i8

source§

impl Eq for i16

source§

impl Eq for i32

source§

impl Eq for i64

source§

impl Eq for i128

source§

impl Eq for isize

source§

impl Eq for !

source§

impl Eq for str

source§

impl Eq for u8

source§

impl Eq for u16

source§

impl Eq for u32

source§

impl Eq for u64

source§

impl Eq for u128

source§

impl Eq for ()

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

source§

impl Eq for TypeId

1.27.0 · source§

impl Eq for CpuidResult

Available on x86 or x86-64 only.
1.34.0 · source§

impl Eq for CharTryFromError

1.9.0 · source§

impl Eq for DecodeUtf16Error

1.20.0 · source§

impl Eq for ParseCharError

1.59.0 · source§

impl Eq for TryFromCharError

source§

impl Eq for CStr

1.69.0 · source§

impl Eq for FromBytesUntilNulError

1.64.0 · source§

impl Eq for FromBytesWithNulError

source§

impl Eq for Error

1.33.0 · source§

impl Eq for PhantomPinned

source§

impl Eq for Assume

source§

impl Eq for AddrParseError

source§

impl Eq for Ipv4Addr

source§

impl Eq for Ipv6Addr

source§

impl Eq for SocketAddrV4

source§

impl Eq for SocketAddrV6

1.34.0 · source§

impl Eq for NonZeroI8

1.34.0 · source§

impl Eq for NonZeroI16

1.34.0 · source§

impl Eq for NonZeroI32

1.34.0 · source§

impl Eq for NonZeroI64

1.34.0 · source§

impl Eq for NonZeroI128

1.34.0 · source§

impl Eq for NonZeroIsize

1.28.0 · source§

impl Eq for NonZeroU8

1.28.0 · source§

impl Eq for NonZeroU16

1.28.0 · source§

impl Eq for NonZeroU32

1.28.0 · source§

impl Eq for NonZeroU64

1.28.0 · source§

impl Eq for NonZeroU128

1.28.0 · source§

impl Eq for NonZeroUsize

source§

impl Eq for ParseFloatError

source§

impl Eq for ParseIntError

1.34.0 · source§

impl Eq for TryFromIntError

source§

impl Eq for RangeFull

source§

impl Eq for core::ptr::Alignment

source§

impl Eq for ParseBoolError

source§

impl Eq for Utf8Error

1.3.0 · source§

impl Eq for Duration

1.66.0 · source§

impl Eq for TryFromFloatSecsError

1.10.0 · source§

impl<'a> Eq for Location<'a>

source§

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

source§

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

source§

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

1.55.0 · source§

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

source§

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

1.4.0 · source§

impl<F: FnPtr> Eq for F

1.29.0 · source§

impl<H> Eq for BuildHasherDefault<H>

source§

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

source§

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

1.26.0 · source§

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

source§

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

1.26.0 · source§

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

1.41.0 · source§

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

source§

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

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

1.21.0 · source§

impl<T> Eq for Discriminant<T>

source§

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

1.2.0 · source§

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

1.20.0 · source§

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

1.17.0 · source§

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

source§

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

1.36.0 · source§

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

source§

impl<T: Eq> Eq for [T]

1.70.0 · source§

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

source§

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

source§

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

1.19.0 · source§

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

source§

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

source§

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

1.2.0 · source§

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

source§

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

source§

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

source§

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

1.25.0 · source§

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

source§

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