Crate type_equalities[][src]

Implements TypeEq that can be passed around and used at runtime to safely coerce values, references and other structures dependending on these types.

The equality type is zero-sized, and the coercion should optimize to a no-op in all cases.

This crate is ![no_std] but still requires access to alloc. This requirement might get lifted in the future.

Modules

details

Details for primitively consuming an equality.

type_functions

TypeFunctions have the amazing property that they can be used to push the equality of a type-level argment through to an equality of the type-level result.

Structs

TypeEq

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

Traits

IsEqual

Equality at a constraint level, as a type alias. Reflexivity holds.

Functions

coerce

Coerce a value of type T to a value of type U, given evidence that T == U.

coerce_box

Coerce a value of type Box<T> to a value of type Box<U>, given evidence that T == U.

coerce_mut

Coerce a value of type &mut T to a value of type &mut U, given evidence that T == U.

coerce_ref

Coerce a value of type &T to a value of type &U, given evidence that T == U.

refl

Construct evidence of the reflexive equality T == T.

substitute

Our workhorse for most of the other coerce implementations, lifting the equality through an arbitrary TypeFunction. Do consider using this before writing a custom Consumer.

trivial_eq

Construct evidence of TypeEq<T, U> under the constraint T: IsEqual<U>.