Trait std::marker::StructuralEq
source · pub trait StructuralEq { }
structural_match
#31434)Expand description
Required trait for constants used in pattern matches.
Any type that derives Eq
automatically implements this trait, regardless
of whether its type parameters implement Eq
.
This is a hack to work around a limitation in our type system.
Background
We want to require that types of consts used in pattern matches
have the attribute #[derive(PartialEq, Eq)]
.
In a more ideal world, we could check that requirement by just checking that
the given type implements both the StructuralPartialEq
trait and
the Eq
trait. However, you can have ADTs that do derive(PartialEq, Eq)
,
and be a case that we want the compiler to accept, and yet the constant’s
type fails to implement Eq
.
Namely, a case like this:
#[derive(PartialEq, Eq)]
struct Wrap<X>(X);
fn higher_order(_: &()) { }
const CFN: Wrap<fn(&())> = Wrap(higher_order);
fn main() {
match CFN {
CFN => {}
_ => {}
}
}
Run(The problem in the above code is that Wrap<fn(&())>
does not implement
PartialEq
, nor Eq
, because for<'a> fn(&'a _)
does not implement those
traits.)
Therefore, we cannot rely on naive check for StructuralPartialEq
and
mere Eq
.
As a hack to work around this, we use two separate traits injected by each
of the two derives (#[derive(PartialEq)]
and #[derive(Eq)]
) and check
that both of them are present as part of structural-match checking.
Implementors§
impl StructuralEq for hashbrown::TryReserveError
impl StructuralEq for AsciiChar
impl StructuralEq for BacktraceStatus
impl StructuralEq for PrintFmt
impl StructuralEq for std::cmp::Ordering
impl StructuralEq for TryReserveErrorKind
impl StructuralEq for VarError
impl StructuralEq for std::fmt::Alignment
impl StructuralEq for SeekFrom
impl StructuralEq for ErrorKind
impl StructuralEq for IpAddr
impl StructuralEq for Ipv6MulticastScope
impl StructuralEq for Shutdown
impl StructuralEq for SocketAddr
impl StructuralEq for FpCategory
impl StructuralEq for IntErrorKind
impl StructuralEq for BacktraceStyle
impl StructuralEq for Which
impl StructuralEq for SearchStep
impl StructuralEq for std::sync::atomic::Ordering
impl StructuralEq for Selected
impl StructuralEq for RecvTimeoutError
impl StructuralEq for TryRecvError
impl StructuralEq for ProgramKind
impl StructuralEq for bool
impl StructuralEq for char
impl StructuralEq for i8
impl StructuralEq for i16
impl StructuralEq for i32
impl StructuralEq for i64
impl StructuralEq for i128
impl StructuralEq for isize
impl StructuralEq for str
impl StructuralEq for u8
impl StructuralEq for u16
impl StructuralEq for u32
impl StructuralEq for u64
impl StructuralEq for u128
impl StructuralEq for ()
impl StructuralEq for usize
impl StructuralEq for CpuidResult
impl StructuralEq for FromBytesUntilNulError
impl StructuralEq for AllocError
impl StructuralEq for Layout
impl StructuralEq for LayoutError
impl StructuralEq for TypeId
impl StructuralEq for CharTryFromError
impl StructuralEq for DecodeUtf16Error
impl StructuralEq for ParseCharError
impl StructuralEq for TryFromCharError
impl StructuralEq for std::collections::TryReserveError
impl StructuralEq for CString
impl StructuralEq for FromBytesWithNulError
impl StructuralEq for FromVecWithNulError
impl StructuralEq for IntoStringError
impl StructuralEq for NulError
impl StructuralEq for Error
impl StructuralEq for std::fs::FileType
impl StructuralEq for Permissions
impl StructuralEq for Assume
impl StructuralEq for AddrParseError
impl StructuralEq for Ipv4Addr
impl StructuralEq for Ipv6Addr
impl StructuralEq for SocketAddrV4
impl StructuralEq for SocketAddrV6
impl StructuralEq for NonZeroI8
impl StructuralEq for NonZeroI16
impl StructuralEq for NonZeroI32
impl StructuralEq for NonZeroI64
impl StructuralEq for NonZeroI128
impl StructuralEq for NonZeroIsize
impl StructuralEq for NonZeroU8
impl StructuralEq for NonZeroU16
impl StructuralEq for NonZeroU32
impl StructuralEq for NonZeroU64
impl StructuralEq for NonZeroU128
impl StructuralEq for NonZeroUsize
impl StructuralEq for ParseFloatError
impl StructuralEq for ParseIntError
impl StructuralEq for TryFromIntError
impl StructuralEq for RangeFull
impl StructuralEq for UCred
impl StructuralEq for InvalidHandleError
impl StructuralEq for NullHandleError
impl StructuralEq for StripPrefixError
impl StructuralEq for std::process::ExitStatus
impl StructuralEq for std::process::ExitStatusError
impl StructuralEq for Output
impl StructuralEq for std::ptr::Alignment
impl StructuralEq for ParseBoolError
impl StructuralEq for Utf8Error
impl StructuralEq for FromUtf8Error
impl StructuralEq for String
impl StructuralEq for WaitTimeoutResult
impl StructuralEq for Operation
impl StructuralEq for RecvError
impl StructuralEq for FilePermissions
impl StructuralEq for std::sys::unix::fs::FileType
impl StructuralEq for ExitCode
impl StructuralEq for std::sys::unix::process::process_inner::ExitStatus
impl StructuralEq for std::sys::unix::process::process_inner::ExitStatusError
impl StructuralEq for std::sys::unix::time::inner::Instant
impl StructuralEq for Nanoseconds
impl StructuralEq for std::sys::unix::time::SystemTime
impl StructuralEq for Timespec
impl StructuralEq for CodePoint
impl StructuralEq for Wtf8
impl StructuralEq for Wtf8Buf
impl StructuralEq for AccessError
impl StructuralEq for ThreadId
impl StructuralEq for Duration
impl StructuralEq for std::time::Instant
impl StructuralEq for std::time::SystemTime
impl StructuralEq for TryFromFloatSecsError
impl StructuralEq for PhantomPinned
impl<'a> StructuralEq for Component<'a>
impl<'a> StructuralEq for Prefix<'a>
impl<'a> StructuralEq for Location<'a>
impl<'a> StructuralEq for PrefixComponent<'a>
impl<'a> StructuralEq for Utf8Chunk<'a>
impl<A, Z, Y, X, W, V, U, T> StructuralEq for (A, Z, Y, X, W, V, U, T)
impl<B, A, Z, Y, X, W, V, U, T> StructuralEq for (B, A, Z, Y, X, W, V, U, T)
impl<B, C> StructuralEq for ControlFlow<B, C>
impl<C, B, A, Z, Y, X, W, V, U, T> StructuralEq for (C, B, A, Z, Y, X, W, V, U, T)
impl<D, C, B, A, Z, Y, X, W, V, U, T> StructuralEq for (D, C, B, A, Z, Y, X, W, V, U, T)
impl<E, D, C, B, A, Z, Y, X, W, V, U, T> StructuralEq for (E, D, C, B, A, Z, Y, X, W, V, U, T)
impl<Idx> StructuralEq for Range<Idx>
impl<Idx> StructuralEq for RangeFrom<Idx>
impl<Idx> StructuralEq for RangeInclusive<Idx>
impl<Idx> StructuralEq for RangeTo<Idx>
impl<Idx> StructuralEq for RangeToInclusive<Idx>
impl<T> StructuralEq for Bound<T>
impl<T> StructuralEq for Option<T>
impl<T> StructuralEq for SendTimeoutError<T>
impl<T> StructuralEq for TrySendError<T>
impl<T> StructuralEq for Poll<T>
impl<T> StructuralEq for &Twhere T: ?Sized,
impl<T> StructuralEq for [T]
impl<T> StructuralEq for (T₁, T₂, …, Tₙ)
This trait is implemented for tuples up to twelve items long.