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 EngineOrModuleTypeIndex
impl Eq for EntityIndex
impl Eq for GlobalInit
impl Eq for Trap
impl Eq for VMGcKind
impl Eq for WasmHeapType
impl Eq for WasmValType
impl Eq for LibCall
impl Eq for BlockType
impl Eq for CanonicalOption
impl Eq for ComdatSymbolKind
impl Eq for ComponentExternalKind
impl Eq for ComponentOuterAliasKind
impl Eq for ComponentTypeRef
impl Eq for ComponentValType
impl Eq for CompositeType
impl Eq for Encoding
impl Eq for ExternalKind
impl Eq for FrameKind
impl Eq for HeapType
impl Eq for InstantiationArgKind
impl Eq for OuterAliasKind
impl Eq for PrimitiveValType
impl Eq for StorageType
impl Eq for TypeBounds
impl Eq for UnpackedIndex
impl Eq for ValType
impl Eq for ComponentNameKind<'_>
impl Eq for AnyTypeId
impl Eq for ComponentAnyTypeId
impl Eq for ComponentCoreTypeId
impl Eq for AsciiChar
impl Eq for wasmtime_environ::__core::cmp::Ordering
impl Eq for Infallible
impl Eq for wasmtime_environ::__core::fmt::Alignment
impl Eq for IpAddr
impl Eq for Ipv6MulticastScope
impl Eq for SocketAddr
impl Eq for FpCategory
impl Eq for IntErrorKind
impl Eq for SearchStep
impl Eq for wasmtime_environ::__core::sync::atomic::Ordering
impl Eq for TryReserveErrorKind
impl Eq for BacktraceStatus
impl Eq for VarError
impl Eq for SeekFrom
impl Eq for ErrorKind
impl Eq for Shutdown
impl Eq for BacktraceStyle
impl Eq for RecvTimeoutError
impl Eq for TryRecvError
impl Eq for hashbrown::TryReserveError
impl Eq for AddressSize
impl Eq for object::common::Architecture
impl Eq for object::common::BinaryFormat
impl Eq for ComdatKind
impl Eq for FileFlags
impl Eq for RelocationEncoding
impl Eq for RelocationFlags
impl Eq for RelocationKind
impl Eq for SectionFlags
impl Eq for SectionKind
impl Eq for object::common::SegmentFlags
impl Eq for SubArchitecture
impl Eq for SymbolKind
impl Eq for SymbolScope
impl Eq for object::endian::Endianness
impl Eq for CompressionFormat
impl Eq for FileKind
impl Eq for ObjectKind
impl Eq for RelocationTarget
impl Eq for SymbolSection
impl Eq for Op
impl Eq for CDataModel
impl Eq for Size
impl Eq for ParseError
impl Eq for Aarch64Architecture
impl Eq for target_lexicon::targets::Architecture
impl Eq for ArmArchitecture
impl Eq for target_lexicon::targets::BinaryFormat
impl Eq for CustomVendor
impl Eq for Environment
impl Eq for Mips32Architecture
impl Eq for Mips64Architecture
impl Eq for OperatingSystem
impl Eq for Riscv32Architecture
impl Eq for Riscv64Architecture
impl Eq for Vendor
impl Eq for X86_32Architecture
impl Eq for CallingConvention
impl Eq for target_lexicon::triple::Endianness
impl Eq for PointerWidth
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 BuiltinFunctionIndex
impl Eq for DataIndex
impl Eq for DefinedFuncIndex
impl Eq for DefinedGlobalIndex
impl Eq for DefinedMemoryIndex
impl Eq for DefinedTableIndex
impl Eq for ElemIndex
impl Eq for FilePos
impl Eq for FuncIndex
impl Eq for FuncRefIndex
impl Eq for Global
impl Eq for GlobalIndex
impl Eq for InstructionAddressMap
impl Eq for Memory
impl Eq for MemoryIndex
impl Eq for ModuleInternedTypeIndex
impl Eq for OwnedMemoryIndex
impl Eq for StaticModuleIndex
impl Eq for Table
impl Eq for TableIndex
impl Eq for Tag
impl Eq for TagIndex
impl Eq for TrapInformation
impl Eq for TypeIndex
impl Eq for WasmFuncType
impl Eq for WasmRefType
impl Eq for ComponentName
impl Eq for KebabStr
impl Eq for KebabString
impl Eq for ArrayType
impl Eq for FieldType
impl Eq for FuncType
impl Eq for GlobalType
impl Eq for Ieee32
impl Eq for Ieee64
impl Eq for MemoryType
impl Eq for PackedIndex
impl Eq for RecGroup
impl Eq for RefType
impl Eq for wasmtime_environ::wasmparser::SegmentFlags
impl Eq for StructType
impl Eq for SubType
impl Eq for wasmtime_environ::wasmparser::SymbolFlags
impl Eq for TableType
impl Eq for V128
impl Eq for AliasableResourceId
impl Eq for ComponentCoreInstanceTypeId
impl Eq for ComponentCoreModuleTypeId
impl Eq for ComponentDefinedTypeId
impl Eq for ComponentFuncTypeId
impl Eq for ComponentInstanceTypeId
impl Eq for ComponentTypeId
impl Eq for ComponentValueTypeId
impl Eq for CoreTypeId
impl Eq for RecGroupId
impl Eq for ResourceId
impl Eq for AllocError
impl Eq for Layout
impl Eq for LayoutError
impl Eq for TypeId
impl Eq for CpuidResult
impl Eq for CharTryFromError
impl Eq for DecodeUtf16Error
impl Eq for ParseCharError
impl Eq for TryFromCharError
impl Eq for CStr
impl Eq for FromBytesUntilNulError
impl Eq for FromBytesWithNulError
impl Eq for wasmtime_environ::__core::fmt::Error
impl Eq for PhantomPinned
impl Eq for Assume
impl Eq for AddrParseError
impl Eq for Ipv4Addr
impl Eq for Ipv6Addr
impl Eq for SocketAddrV4
impl Eq for SocketAddrV6
impl Eq for ParseFloatError
impl Eq for ParseIntError
impl Eq for TryFromIntError
impl Eq for RangeFull
impl Eq for wasmtime_environ::__core::ptr::Alignment
impl Eq for ParseBoolError
impl Eq for Utf8Error
impl Eq for Duration
impl Eq for TryFromFloatSecsError
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 FromUtf8Error
impl Eq for String
impl Eq for OsStr
impl Eq for OsString
impl Eq for FileType
impl Eq for Permissions
impl Eq for 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 WaitTimeoutResult
impl Eq for RecvError
impl Eq for AccessError
impl Eq for ThreadId
impl Eq for Instant
impl Eq for SystemTime
impl Eq for indexmap::TryReserveError
impl Eq for BigEndian
impl Eq for LittleEndian
impl Eq for CompressedFileRange
impl Eq for object::read::Error
impl Eq for SectionIndex
impl Eq for SymbolIndex
impl Eq for BuildMetadata
impl Eq for Comparator
impl Eq for Prerelease
impl Eq for Version
impl Eq for VersionReq
impl Eq for DefaultToHost
impl Eq for DefaultToUnknown
impl Eq for Triple
impl<'a> Eq for FlagValue<'a>
impl<'a> Eq for ComponentDefinedType<'a>
impl<'a> Eq for Component<'a>
impl<'a> Eq for Prefix<'a>
impl<'a> Eq for DependencyName<'a>
impl<'a> Eq for HashName<'a>
impl<'a> Eq for InterfaceName<'a>
impl<'a> Eq for ResourceFunc<'a>
impl<'a> Eq for UrlName<'a>
impl<'a> Eq for VariantCase<'a>
impl<'a> Eq for Location<'a>
impl<'a> Eq for Utf8Chunk<'a>
impl<'a> Eq for PrefixComponent<'a>
impl<'data> Eq for CodeView<'data>
impl<'data> Eq for CompressedData<'data>
impl<'data> Eq for Export<'data>
impl<'data> Eq for Import<'data>
impl<'data> Eq for ObjectMapEntry<'data>
impl<'data> Eq for SymbolMapName<'data>
impl<'data> Eq for Bytes<'data>
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<E> Eq for I16<E>
impl<E> Eq for I32<E>
impl<E> Eq for I64<E>
impl<E> Eq for U16<E>
impl<E> Eq for U32<E>
impl<E> Eq for U64<E>
impl<E> Eq for I16Bytes<E>
impl<E> Eq for I32Bytes<E>
impl<E> Eq for I64Bytes<E>
impl<E> Eq for U16Bytes<E>
impl<E> Eq for U32Bytes<E>
impl<E> Eq for U64Bytes<E>
impl<F> Eq for Fwhere
F: FnPtr,
impl<H> Eq for BuildHasherDefault<H>
impl<Idx> Eq for Range<Idx>where
Idx: Eq,
impl<Idx> Eq for RangeFrom<Idx>where
Idx: Eq,
impl<Idx> Eq for 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> Eq for PrimaryMap<K, V>
impl<K, V> Eq for SecondaryMap<K, V>
impl<K, V> Eq for indexmap::map::slice::Slice<K, V>
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> Eq for IndexMap<K, V, S>
impl<K, V, S, A> Eq for hashbrown::map::HashMap<K, V, S, A>
impl<Ptr> Eq for Pin<Ptr>
impl<Section, Symbol> Eq for object::common::SymbolFlags<Section, Symbol>
impl<T> Eq for Bound<T>where
T: Eq,
impl<T> Eq for Option<T>where
T: Eq,
impl<T> Eq for Poll<T>where
T: Eq,
impl<T> Eq for TrySendError<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.