TypeEq

Struct TypeEq 

Source
pub struct TypeEq<T: ?Sized, U: ?Sized> { /* private fields */ }
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§

Source§

impl<T: ?Sized> TypeEq<T, T>

Source

pub const fn refl() -> TypeEq<T, T>

Same as crate::refl.

Source§

impl<T: ?Sized, U: ?Sized> TypeEq<T, U>

Source

pub const fn trivial() -> Self
where T: IsEqual<U>,

Same as crate::trivial_eq.

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

Source

pub fn substitute<F: TypeFunction<T> + TypeFunction<U>>( self, t: ApF<F, T>, ) -> ApF<F, U>
where ApF<F, T>: Sized, ApF<F, U>: Sized,

Source

pub fn coerce(self, t: T) -> U
where T: Sized, U: Sized,

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

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

pub fn lift_through<F: TypeFunction<T> + TypeFunction<U>>( self, ) -> TypeEq<ApF<F, T>, ApF<F, U>>

Lift the type equality through any TypeFunction

Source

pub fn invert(self) -> TypeEq<U, T>

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

Source

pub fn trans<V: ?Sized>(self, rhs: TypeEq<U, V>) -> TypeEq<T, V>

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

Source§

impl<T: ?Sized, U: ?Sized> TypeEq<T, U>

Source

pub fn use_eq<C: Consumer<T, U>>(self, c: C) -> C::Result

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

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

Trait Implementations§

Source§

impl<T: ?Sized, U: ?Sized> Clone for TypeEq<T, U>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: ?Sized, U: ?Sized> Copy for TypeEq<T, U>

Auto Trait Implementations§

§

impl<T, U> Freeze for TypeEq<T, U>
where T: ?Sized, U: ?Sized,

§

impl<T, U> !RefUnwindSafe for TypeEq<T, U>

§

impl<T, U> !Send for TypeEq<T, U>

§

impl<T, U> !Sync for TypeEq<T, U>

§

impl<T, U> Unpin for TypeEq<T, U>
where T: ?Sized, U: ?Sized,

§

impl<T, U> !UnwindSafe for TypeEq<T, U>

Blanket Implementations§

Source§

impl<T> AliasSelf for T
where T: ?Sized,

Source§

type Alias = T

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

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> IsEqual<U> for T
where T: AliasSelf<Alias = U> + ?Sized, U: ?Sized,