[][src]Trait wasmer_types::entity::__core::marker::StructuralEq

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

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 workaround 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 (1.) the StructuralPartialEq trait and (2.) 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 ExportIndex[src]

impl StructuralEq for ExternType[src]

impl StructuralEq for ImportIndex[src]

impl StructuralEq for Mutability[src]

impl StructuralEq for Type[src]

impl StructuralEq for Bytes[src]

impl StructuralEq for CustomSectionIndex[src]

impl StructuralEq for DataIndex[src]

impl StructuralEq for ElemIndex[src]

impl StructuralEq for Features[src]

impl StructuralEq for FunctionIndex[src]

impl StructuralEq for FunctionType[src]

impl StructuralEq for GlobalIndex[src]

impl StructuralEq for GlobalType[src]

impl StructuralEq for LocalFunctionIndex[src]

impl StructuralEq for LocalGlobalIndex[src]

impl StructuralEq for LocalMemoryIndex[src]

impl StructuralEq for LocalTableIndex[src]

impl StructuralEq for MemoryIndex[src]

impl StructuralEq for MemoryType[src]

impl StructuralEq for Pages[src]

impl StructuralEq for SignatureIndex[src]

impl StructuralEq for TableIndex[src]

impl StructuralEq for TableType[src]

impl StructuralEq for V128[src]

impl<T> StructuralEq for ExportType<T>[src]

impl<T> StructuralEq for ImportType<T>[src]

Loading content...