Expand description
Ready-made type-level values: Peano naturals, booleans, and
heterogeneous lists, all implementing
Reflect.
Where reify-reflect-core
defines the Reflect trait and the
RuntimeValue vocabulary, this
crate provides the most useful concrete instances of that trait, the
ones you reach for first when prototyping type-level code.
All of these types are zero-sized: they exist only at compile time
and disappear at runtime. The Reflect
impls are what give you a runtime handle on the value they encode.
§What’s in here
§Peano naturals
Zis zero,S<N>is “successor ofN”.Add,Mul, andLtperform type-level arithmetic.N0throughN8are convenience aliases for the small numbers.- The
Nattrait gives you a runtimeu64for any of these types, and theReflectimpl produces aRuntimeValue::Nat.
§Type-level booleans
TrueandFalse.Not,And,Orperform compile-time boolean logic at the trait level.- Both reflect to a plain
bool.
§Heterogeneous lists
HNilis the empty list,HCons<H, T>is a cons cell.- The
HListtrait exposeslen()andis_empty()at the type level. - When every element implements
Reflect<Value = RuntimeValue>, the whole HList reflects to aVec<RuntimeValue>.
§Optional bridges (feature-gated)
frunk: interoperate withfrunk’sHList.typenum: bridge betweenNatandtypenum’sUnsigned.
§Examples
use reflect_nat::{Z, S, True, HNil, HCons};
use reify_reflect_core::{Reflect, RuntimeValue};
// Type-level natural: 3
type Three = S<S<S<Z>>>;
assert_eq!(Three::reflect(), RuntimeValue::Nat(3));
// Type-level boolean
assert_eq!(True::reflect(), true);
// Type-level HList: [3, 0]
type MyList = HCons<Three, HCons<Z, HNil>>;
assert_eq!(
MyList::reflect(),
vec![RuntimeValue::Nat(3), RuntimeValue::Nat(0)]
);See also: reflect-derive for
#[derive(Reflect)] on your own structs and enums (which can include
the types from this crate as fields), and
const-reify for going the other
direction (runtime u64 to const generic).
Structs§
- False
- Type-level
false. - HCons
- A cons cell for heterogeneous lists.
HCons<H, T>prepends headHto tailT. - HNil
- The empty heterogeneous list.
- S
- Type-level successor.
S<N>representsN + 1. - True
- Type-level
true. - Z
- Type-level zero.
Traits§
- Add
- Type-level addition.
Add<A, B>computesA + B. - And
- Type-level boolean AND.
- Bool
- Marker trait for type-level booleans.
- HList
- Marker trait for type-level heterogeneous lists.
- Lt
- Type-level less-than comparison.
Lt<A, B>is true whenA < B. - Mul
- Type-level multiplication.
Mul<A, B>computesA * B. - Nat
- Marker trait for types that represent type-level natural numbers.
- Not
- Type-level boolean NOT.
- Or
- Type-level boolean OR.