Struct type_equalities::TypeEq[][src]

pub struct TypeEq<T: ?Sized, U: ?Sized> { /* fields omitted */ }
Expand description

Evidence of the equality T == U as a zero-sized type.

assert_eq!(core::mem::size_of::<TypeEq<T, U>>(), 0);

It is important to note that the TypeEq is invariant in both arguments.

fn coerce_lt<'a, 'b: 'a, T>(eq: TypeEq<&'b T, &'b T>)
    -> TypeEq<&'b T, &'a T>
{
    eq
}
fn coerce_lt_inv<'a, 'b: 'a, T>(eq: TypeEq<&'a T, &'a T>)
    -> TypeEq<&'a T, &'b T>
{
    eq
}

Unsizing also does not work for TypeEq.

fn coerce_dyn<T: core::fmt::Debug>(eq: &TypeEq<T, T>)
    -> &TypeEq<T, dyn core::fmt::Debug>
{
    eq
}

Implementations

Same as crate::refl.

Same as crate::trivial_eq.

Note: this function is const only on nightly, since it depends on the const_fn_trait_bound feature.

Same as crate::coerce. Note that this is operationally a no-op.

Examples
assert_eq!(refl().coerce(42), 42);

Lift the type equality through any TypeFunction

Get the inverse equality. T == U ==> U == T

Apply transitivity. T == U & U == V ==> T == V

Use the observed equality to call the consumer to compute a result.

Consider using either TypeEq::coerce or TypeEq::lift_through first.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Always set to Self, but the type checker doesn’t reduce T::Alias to T.

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.