Crate type_equalities

Source
Expand description

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]. You can optionally turn off the alloc feature.

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 argument 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_boxalloc
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.
maybe_type_eqtest-for-type-equality
Optionally obtain a type equality if the type checker can solve 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>.