Trait std::marker::StructuralEq[][src]

#[lang = "structural_teq"]pub trait StructuralEq { }
🔬 This is a nightly-only experimental API. (structural_match #31434)

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.

Implementations on Foreign Types

impl StructuralEq for CpuidResult[src]

impl<'a> StructuralEq for Utf8LossyChunk<'a>[src]

Loading content...

Implementors

impl StructuralEq for BacktraceStatus[src]

impl StructuralEq for TryReserveError[src]

impl StructuralEq for VarError1.0.0[src]

impl StructuralEq for ErrorKind1.0.0[src]

impl StructuralEq for SeekFrom1.0.0[src]

impl StructuralEq for IpAddr1.7.0[src]

impl StructuralEq for Ipv6MulticastScope[src]

impl StructuralEq for Shutdown1.0.0[src]

impl StructuralEq for SocketAddr1.0.0[src]

impl StructuralEq for FpCategory1.0.0[src]

impl StructuralEq for IntErrorKind[src]

impl StructuralEq for SearchStep[src]

impl StructuralEq for Ordering1.0.0[src]

impl StructuralEq for RecvTimeoutError1.12.0[src]

impl StructuralEq for TryRecvError1.0.0[src]

impl StructuralEq for AllocError[src]

impl StructuralEq for Layout1.28.0[src]

impl StructuralEq for LayoutError1.50.0[src]

impl StructuralEq for TypeId1.0.0[src]

impl StructuralEq for CharTryFromError1.34.0[src]

impl StructuralEq for DecodeUtf16Error1.9.0[src]

impl StructuralEq for ParseCharError1.20.0[src]

impl StructuralEq for CString1.0.0[src]

impl StructuralEq for FromBytesWithNulError1.10.0[src]

impl StructuralEq for FromVecWithNulError[src]

impl StructuralEq for IntoStringError1.7.0[src]

impl StructuralEq for NulError1.0.0[src]

impl StructuralEq for Error1.0.0[src]

impl StructuralEq for FileType1.1.0[src]

impl StructuralEq for Permissions1.0.0[src]

impl StructuralEq for PhantomPinned1.33.0[src]

impl StructuralEq for AddrParseError1.0.0[src]

impl StructuralEq for NonZeroI81.34.0[src]

impl StructuralEq for NonZeroI161.34.0[src]

impl StructuralEq for NonZeroI321.34.0[src]

impl StructuralEq for NonZeroI641.34.0[src]

impl StructuralEq for NonZeroI1281.34.0[src]

impl StructuralEq for NonZeroIsize1.34.0[src]

impl StructuralEq for NonZeroU81.28.0[src]

impl StructuralEq for NonZeroU161.28.0[src]

impl StructuralEq for NonZeroU321.28.0[src]

impl StructuralEq for NonZeroU641.28.0[src]

impl StructuralEq for NonZeroU1281.28.0[src]

impl StructuralEq for NonZeroUsize1.28.0[src]

impl StructuralEq for ParseFloatError1.0.0[src]

impl StructuralEq for ParseIntError1.0.0[src]

impl StructuralEq for TryFromIntError1.34.0[src]

impl StructuralEq for RangeFull1.0.0[src]

impl StructuralEq for NoneError[src]

impl StructuralEq for UCred[src]

This is supported on Unix only.

impl StructuralEq for StripPrefixError1.7.0[src]

impl StructuralEq for ExitStatus1.0.0[src]

impl StructuralEq for Output1.0.0[src]

impl StructuralEq for ParseBoolError1.0.0[src]

impl StructuralEq for Utf8Error1.0.0[src]

impl StructuralEq for FromUtf8Error1.0.0[src]

impl StructuralEq for String1.0.0[src]

impl StructuralEq for RecvError1.0.0[src]

impl StructuralEq for WaitTimeoutResult1.5.0[src]

impl StructuralEq for AccessError1.26.0[src]

impl StructuralEq for ThreadId1.19.0[src]

impl StructuralEq for Duration1.3.0[src]

impl StructuralEq for Instant1.8.0[src]

impl StructuralEq for SystemTime1.8.0[src]

impl<'a> StructuralEq for Component<'a>1.0.0[src]

impl<'a> StructuralEq for Prefix<'a>1.0.0[src]

impl<'a> StructuralEq for Location<'a>1.10.0[src]

impl<'a> StructuralEq for PrefixComponent<'a>1.0.0[src]

impl<Idx> StructuralEq for Range<Idx>1.0.0[src]

impl<Idx> StructuralEq for RangeFrom<Idx>1.0.0[src]

impl<Idx> StructuralEq for RangeInclusive<Idx>1.26.0[src]

impl<Idx> StructuralEq for RangeTo<Idx>1.0.0[src]

impl<Idx> StructuralEq for RangeToInclusive<Idx>1.26.0[src]

impl<T> StructuralEq for Bound<T>1.17.0[src]

impl<T> StructuralEq for Option<T>1.0.0[src]

impl<T> StructuralEq for TrySendError<T>1.0.0[src]

impl<T> StructuralEq for Poll<T>1.36.0[src]

impl<T> StructuralEq for Reverse<T>1.19.0[src]

impl<T> StructuralEq for BTreeSet<T>1.0.0[src]

impl<T> StructuralEq for Cursor<T>1.0.0[src]

impl<T> StructuralEq for PhantomData<T> where
    T: ?Sized
[src]

impl<T> StructuralEq for ManuallyDrop<T> where
    T: ?Sized
1.20.0[src]

impl<T> StructuralEq for Wrapping<T>1.0.0[src]

impl<T> StructuralEq for SendError<T>1.0.0[src]

impl<T, E> StructuralEq for Result<T, E>1.0.0[src]

impl<Y, R> StructuralEq for GeneratorState<Y, R>[src]

Loading content...