Crate type_equalities[][src]

Implements type equalities 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.

Structs

ComposeF

Composition for TypeFunctions, i.e. ApF<ComposeF<F, G>, T> == ApF<F, ApF<G, T>>

IdF

Implements the identity TypeFunction, mapping types to itself. Coercing through this gives us the basic safe transmute.

LoefIdF

Implements a TypeFunction version of the Martin-Löf identity type, i.e. ApF<LoefIdF<T>, U> == TypeEq<T, U>.

MutRefF

Implements the TypeFunction ApF<MutRefF<'a>, A> == &'a mut A

RefF

Implements the TypeFunction ApF<RefF<'a>, A> == &'a A

TypeEq

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

Traits

AliasSelf

Trait used to convince the rust type checker of the claimed equality

Consumer

A consumer recives evidence of a type equality T == U and computes a result.

TypeFunction

A trait mapping type arguments to results. Note that Self is used only as a marker. See also substitute, which implements coercing of results.

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.

lift_equality

Lift the type equality through any TypeFunction

refl

Construct evidence of the reflexive equality T == T.

substitute

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

Type Definitions

ApF

The result of applying the TypeFunction F to T.