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
- [
Z] is zero, [S<N>] is "successor ofN". - [
Add], [Mul], and [Lt] perform type-level arithmetic. - [
N0] through [N8] are convenience aliases for the small numbers. - The [
Nat] trait gives you a runtime [u64] for any of these types, and theReflectimpl produces aRuntimeValue::Nat.
Type-level booleans
- [
True] and [False]. - [
Not], [And], [Or] perform compile-time boolean logic at the trait level. - Both reflect to a plain [
prim@bool].
Heterogeneous lists
- [
HNil] is the empty list, [HCons<H, T>] is a cons cell. - The [
HList] trait 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 between [Nat] andtypenum'sUnsigned.
Examples
use ;
use ;
// Type-level natural: 3
type Three = ;
assert_eq!;
// Type-level boolean
assert_eq!;
// Type-level HList: [3, 0]
type MyList = ;
assert_eq!;
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).