pub trait StructuralEq { }
🔬This is a nightly-only experimental API. (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§

source§

impl StructuralEq for byte_slice_cast::Error

source§

impl StructuralEq for PathError

source§

impl StructuralEq for TypeDefPrimitive

source§

impl StructuralEq for MetaForm

source§

impl StructuralEq for PortableForm

1.0.0 · source§

impl StructuralEq for scale_info::prelude::cmp::Ordering

source§

impl StructuralEq for TryReserveErrorKind

1.28.0 · source§

impl StructuralEq for scale_info::prelude::fmt::Alignment

1.0.0 · source§

impl StructuralEq for FpCategory

1.55.0 · source§

impl StructuralEq for IntErrorKind

source§

impl StructuralEq for AsciiChar

source§

impl StructuralEq for Which

1.7.0 · source§

impl StructuralEq for IpAddr

source§

impl StructuralEq for Ipv6MulticastScope

1.0.0 · source§

impl StructuralEq for SocketAddr

source§

impl StructuralEq for SearchStep

1.0.0 · source§

impl StructuralEq for core::sync::atomic::Ordering

1.65.0 · source§

impl StructuralEq for BacktraceStatus

1.0.0 · source§

impl StructuralEq for VarError

1.0.0 · source§

impl StructuralEq for SeekFrom

1.0.0 · source§

impl StructuralEq for ErrorKind

1.0.0 · source§

impl StructuralEq for Shutdown

source§

impl StructuralEq for BacktraceStyle

1.12.0 · source§

impl StructuralEq for RecvTimeoutError

1.0.0 · source§

impl StructuralEq for TryRecvError

source§

impl StructuralEq for bool

source§

impl StructuralEq for char

source§

impl StructuralEq for i8

source§

impl StructuralEq for i16

source§

impl StructuralEq for i32

source§

impl StructuralEq for i64

source§

impl StructuralEq for i128

source§

impl StructuralEq for isize

source§

impl StructuralEq for str

source§

impl StructuralEq for u8

source§

impl StructuralEq for u16

source§

impl StructuralEq for u32

source§

impl StructuralEq for u64

source§

impl StructuralEq for u128

source§

impl StructuralEq for ()

source§

impl StructuralEq for usize

source§

impl StructuralEq for Lsb0

source§

impl StructuralEq for Msb0

source§

impl StructuralEq for OptionBool

source§

impl StructuralEq for parity_scale_codec::error::Error

source§

impl StructuralEq for Const

source§

impl StructuralEq for Mut

source§

impl StructuralEq for NullPtrError

source§

impl StructuralEq for PortableRegistry

source§

impl StructuralEq for Registry

1.0.0 · source§

impl StructuralEq for TypeId

1.57.0 · source§

impl StructuralEq for TryReserveError

1.0.0 · source§

impl StructuralEq for scale_info::prelude::fmt::Error

source§

impl StructuralEq for Assume

1.34.0 · source§

impl StructuralEq for NonZeroI8

1.34.0 · source§

impl StructuralEq for NonZeroI16

1.34.0 · source§

impl StructuralEq for NonZeroI32

1.34.0 · source§

impl StructuralEq for NonZeroI64

1.34.0 · source§

impl StructuralEq for NonZeroI128

1.34.0 · source§

impl StructuralEq for NonZeroIsize

1.28.0 · source§

impl StructuralEq for NonZeroU8

1.28.0 · source§

impl StructuralEq for NonZeroU16

1.28.0 · source§

impl StructuralEq for NonZeroU32

1.28.0 · source§

impl StructuralEq for NonZeroU64

1.28.0 · source§

impl StructuralEq for NonZeroU128

1.28.0 · source§

impl StructuralEq for NonZeroUsize

1.0.0 · source§

impl StructuralEq for ParseFloatError

1.0.0 · source§

impl StructuralEq for ParseIntError

1.34.0 · source§

impl StructuralEq for TryFromIntError

1.0.0 · source§

impl StructuralEq for RangeFull

1.0.0 · source§

impl StructuralEq for FromUtf8Error

1.0.0 · source§

impl StructuralEq for String

1.64.0 · source§

impl StructuralEq for CString

1.64.0 · source§

impl StructuralEq for FromVecWithNulError

1.64.0 · source§

impl StructuralEq for IntoStringError

1.64.0 · source§

impl StructuralEq for NulError

1.28.0 · source§

impl StructuralEq for Layout

1.50.0 · source§

impl StructuralEq for LayoutError

source§

impl StructuralEq for AllocError

1.34.0 · source§

impl StructuralEq for CharTryFromError

1.20.0 · source§

impl StructuralEq for ParseCharError

1.9.0 · source§

impl StructuralEq for DecodeUtf16Error

1.59.0 · source§

impl StructuralEq for TryFromCharError

1.69.0 · source§

impl StructuralEq for FromBytesUntilNulError

1.64.0 · source§

impl StructuralEq for FromBytesWithNulError

1.0.0 · source§

impl StructuralEq for Ipv4Addr

1.0.0 · source§

impl StructuralEq for Ipv6Addr

1.0.0 · source§

impl StructuralEq for AddrParseError

1.0.0 · source§

impl StructuralEq for SocketAddrV4

1.0.0 · source§

impl StructuralEq for SocketAddrV6

source§

impl StructuralEq for core::ptr::alignment::Alignment

1.0.0 · source§

impl StructuralEq for ParseBoolError

1.0.0 · source§

impl StructuralEq for Utf8Error

1.3.0 · source§

impl StructuralEq for Duration

1.66.0 · source§

impl StructuralEq for TryFromFloatSecsError

1.1.0 · source§

impl StructuralEq for FileType

1.0.0 · source§

impl StructuralEq for Permissions

source§

impl StructuralEq for UCred

1.7.0 · source§

impl StructuralEq for StripPrefixError

1.0.0 · source§

impl StructuralEq for ExitStatus

source§

impl StructuralEq for ExitStatusError

1.0.0 · source§

impl StructuralEq for Output

1.5.0 · source§

impl StructuralEq for WaitTimeoutResult

1.0.0 · source§

impl StructuralEq for RecvError

1.26.0 · source§

impl StructuralEq for AccessError

1.19.0 · source§

impl StructuralEq for ThreadId

1.8.0 · source§

impl StructuralEq for Instant

1.8.0 · source§

impl StructuralEq for SystemTime

1.33.0 · source§

impl StructuralEq for PhantomPinned

1.0.0 · source§

impl<'a> StructuralEq for Component<'a>

1.0.0 · source§

impl<'a> StructuralEq for Prefix<'a>

1.10.0 · source§

impl<'a> StructuralEq for Location<'a>

source§

impl<'a> StructuralEq for Utf8Chunk<'a>

1.0.0 · source§

impl<'a> StructuralEq for PrefixComponent<'a>

source§

impl<'a, T> StructuralEq for CompactRef<'a, T>

source§

impl<'a, T> StructuralEq for Symbol<'a, T>

source§

impl<'a, T, O> StructuralEq for IterOnes<'a, T, O>where T: 'a + BitStore, O: BitOrder,

source§

impl<'a, T, O> StructuralEq for IterZeros<'a, T, O>where T: 'a + BitStore, O: BitOrder,

1.55.0 · source§

impl<B, C> StructuralEq for ControlFlow<B, C>

1.0.0 · source§

impl<Idx> StructuralEq for Range<Idx>

1.0.0 · source§

impl<Idx> StructuralEq for RangeFrom<Idx>

1.26.0 · source§

impl<Idx> StructuralEq for RangeInclusive<Idx>

1.0.0 · source§

impl<Idx> StructuralEq for RangeTo<Idx>

1.26.0 · source§

impl<Idx> StructuralEq for RangeToInclusive<Idx>

source§

impl<Inner> StructuralEq for Frozen<Inner>where Inner: Mutability,

source§

impl<R> StructuralEq for BitEnd<R>where R: BitRegister,

source§

impl<R> StructuralEq for BitIdx<R>where R: BitRegister,

source§

impl<R> StructuralEq for BitIdxError<R>where R: BitRegister,

source§

impl<R> StructuralEq for BitMask<R>where R: BitRegister,

source§

impl<R> StructuralEq for BitPos<R>where R: BitRegister,

source§

impl<R> StructuralEq for BitSel<R>where R: BitRegister,

source§

impl<T> StructuralEq for BitPtrError<T>where T: BitStore,

source§

impl<T> StructuralEq for BitSpanError<T>where T: BitStore,

1.17.0 · source§

impl<T> StructuralEq for Bound<T>

1.0.0 · source§

impl<T> StructuralEq for Option<T>

1.36.0 · source§

impl<T> StructuralEq for Poll<T>

1.0.0 · source§

impl<T> StructuralEq for TrySendError<T>

source§

impl<T> StructuralEq for &Twhere T: ?Sized,

source§

impl<T> StructuralEq for [T]

source§

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

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

source§

impl<T> StructuralEq for CapacityError<T>

source§

impl<T> StructuralEq for MisalignError<T>

source§

impl<T> StructuralEq for Compact<T>

source§

impl<T> StructuralEq for Interner<T>

source§

impl<T> StructuralEq for UntrackedSymbol<T>

1.19.0 · source§

impl<T> StructuralEq for Reverse<T>

1.20.0 · source§

impl<T> StructuralEq for ManuallyDrop<T>where T: ?Sized,

source§

impl<T> StructuralEq for Saturating<T>

1.0.0 · source§

impl<T> StructuralEq for Wrapping<T>

1.0.0 · source§

impl<T> StructuralEq for Cursor<T>

1.0.0 · source§

impl<T> StructuralEq for SendError<T>

source§

impl<T> StructuralEq for PhantomData<T>where T: ?Sized,

1.0.0 · source§

impl<T, E> StructuralEq for Result<T, E>

source§

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

source§

impl<T: Form> StructuralEq for TypeDef<T>

source§

impl<T: Form> StructuralEq for Field<T>

source§

impl<T: Form> StructuralEq for Path<T>

source§

impl<T: Form> StructuralEq for Type<T>

source§

impl<T: Form> StructuralEq for TypeDefArray<T>

source§

impl<T: Form> StructuralEq for TypeDefBitSequence<T>

source§

impl<T: Form> StructuralEq for TypeDefCompact<T>

source§

impl<T: Form> StructuralEq for TypeDefComposite<T>

source§

impl<T: Form> StructuralEq for TypeDefSequence<T>

source§

impl<T: Form> StructuralEq for TypeDefTuple<T>

source§

impl<T: Form> StructuralEq for TypeDefVariant<T>

source§

impl<T: Form> StructuralEq for TypeParameter<T>

source§

impl<T: Form> StructuralEq for Variant<T>

source§

impl<Y, R> StructuralEq for GeneratorState<Y, R>