Trait scale_info::prelude::marker::StructuralEq
source · pub trait StructuralEq { }
structural_match
)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 => {}
_ => {}
}
}
(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 byte_slice_cast::Error
impl StructuralEq for PathError
impl StructuralEq for TypeDefPrimitive
impl StructuralEq for MetaForm
impl StructuralEq for PortableForm
impl StructuralEq for scale_info::prelude::cmp::Ordering
impl StructuralEq for TryReserveErrorKind
impl StructuralEq for scale_info::prelude::fmt::Alignment
impl StructuralEq for FpCategory
impl StructuralEq for IntErrorKind
impl StructuralEq for AsciiChar
impl StructuralEq for Which
impl StructuralEq for IpAddr
impl StructuralEq for Ipv6MulticastScope
impl StructuralEq for SocketAddr
impl StructuralEq for SearchStep
impl StructuralEq for core::sync::atomic::Ordering
impl StructuralEq for BacktraceStatus
impl StructuralEq for VarError
impl StructuralEq for SeekFrom
impl StructuralEq for ErrorKind
impl StructuralEq for Shutdown
impl StructuralEq for BacktraceStyle
impl StructuralEq for RecvTimeoutError
impl StructuralEq for TryRecvError
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 Lsb0
impl StructuralEq for Msb0
impl StructuralEq for OptionBool
impl StructuralEq for parity_scale_codec::error::Error
impl StructuralEq for Const
impl StructuralEq for Mut
impl StructuralEq for NullPtrError
impl StructuralEq for PortableRegistry
impl StructuralEq for Registry
impl StructuralEq for TypeId
impl StructuralEq for TryReserveError
impl StructuralEq for scale_info::prelude::fmt::Error
impl StructuralEq for Assume
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 FromUtf8Error
impl StructuralEq for String
impl StructuralEq for CString
impl StructuralEq for FromVecWithNulError
impl StructuralEq for IntoStringError
impl StructuralEq for NulError
impl StructuralEq for Layout
impl StructuralEq for LayoutError
impl StructuralEq for AllocError
impl StructuralEq for CharTryFromError
impl StructuralEq for ParseCharError
impl StructuralEq for DecodeUtf16Error
impl StructuralEq for TryFromCharError
impl StructuralEq for FromBytesUntilNulError
impl StructuralEq for FromBytesWithNulError
impl StructuralEq for Ipv4Addr
impl StructuralEq for Ipv6Addr
impl StructuralEq for AddrParseError
impl StructuralEq for SocketAddrV4
impl StructuralEq for SocketAddrV6
impl StructuralEq for core::ptr::alignment::Alignment
impl StructuralEq for ParseBoolError
impl StructuralEq for Utf8Error
impl StructuralEq for Duration
impl StructuralEq for TryFromFloatSecsError
impl StructuralEq for FileType
impl StructuralEq for Permissions
impl StructuralEq for UCred
impl StructuralEq for StripPrefixError
impl StructuralEq for ExitStatus
impl StructuralEq for ExitStatusError
impl StructuralEq for Output
impl StructuralEq for WaitTimeoutResult
impl StructuralEq for RecvError
impl StructuralEq for AccessError
impl StructuralEq for ThreadId
impl StructuralEq for Instant
impl StructuralEq for SystemTime
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 Utf8Chunk<'a>
impl<'a> StructuralEq for PrefixComponent<'a>
impl<'a, T> StructuralEq for CompactRef<'a, T>
impl<'a, T> StructuralEq for Symbol<'a, T>
impl<'a, T, O> StructuralEq for IterOnes<'a, T, O>where T: 'a + BitStore, O: BitOrder,
impl<'a, T, O> StructuralEq for IterZeros<'a, T, O>where T: 'a + BitStore, O: BitOrder,
impl<B, C> StructuralEq for ControlFlow<B, C>
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<Inner> StructuralEq for Frozen<Inner>where Inner: Mutability,
impl<R> StructuralEq for BitEnd<R>where R: BitRegister,
impl<R> StructuralEq for BitIdx<R>where R: BitRegister,
impl<R> StructuralEq for BitIdxError<R>where R: BitRegister,
impl<R> StructuralEq for BitMask<R>where R: BitRegister,
impl<R> StructuralEq for BitPos<R>where R: BitRegister,
impl<R> StructuralEq for BitSel<R>where R: BitRegister,
impl<T> StructuralEq for BitPtrError<T>where T: BitStore,
impl<T> StructuralEq for BitSpanError<T>where T: BitStore,
impl<T> StructuralEq for Bound<T>
impl<T> StructuralEq for Option<T>
impl<T> StructuralEq for Poll<T>
impl<T> StructuralEq for TrySendError<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.