Skip to main content

Crate reify_reflect

Crate reify_reflect 

Source
Expand description

A unified, fully-safe ecosystem for moving values between Rust’s type level and value level.

This is the facade crate. It re-exports each of the focused crates in the workspace under a single namespace, so a single dependency on reify-reflect (with appropriate features) is enough to use everything. If you only need one piece, depending on the focused crate directly gives you a smaller build.

§What is “reification” and “reflection”?

Two complementary directions:

  • Reflection is type → value. A type like S<S<S<Z>>> encodes the number 3 at compile time; core::Reflect::reflect hands you 3 at runtime.
  • Reification is value → type. A u64 known only at runtime can be lifted into a callback in which it is genuinely a const N: u64. See const_reify (re-exported as [const_bridge] when the const-reify feature is enabled).

Everything here is #![deny(unsafe_code)]. There is no unsafe, no compiler-internal layout assumption, and no unsafeCoerce-style trick. The Rust borrow checker enforces what GHC’s parametricity enforces in Haskell’s reflection library.

§Module map

ModuleCrateUse it for
corereify_reflect_coreThe Reflect trait, the reify scoping function, the Reified branded token, and the RuntimeValue enum.
natreflect_natPeano naturals (Z/S<N>), type-level booleans, heterogeneous lists, with optional frunk/typenum bridges.
graphreify_graphConvert Rc<RefCell<T>> or Arc<Mutex<T>> graphs to and from a flat node+edge form, preserving sharing and cycles.
contextcontext_traitSwap out Ord, Hash, Display (or any user-defined trait) for one block of code via WithContext.
async_traceasync_reifyWrap futures to record poll events and turn them into an inspectable async step graph.
[const_bridge] (feature const-reify)const_reifyDispatch a runtime u64 in 0..=255 to the matching const N: u64 monomorphization, safely.

For the #[derive(Reflect)], #[trace_async], and #[reifiable] proc macros, depend on reflect-derive, async-reify-macros, and const-reify-derive respectively (or enable the relevant features).

§Quick start

Reflect a type-level number to a runtime value:

use reify_reflect::core::{Reflect, RuntimeValue};
use reify_reflect::nat::{S, Z};

type Three = S<S<S<Z>>>;
assert_eq!(Three::reflect(), RuntimeValue::Nat(3));

For deeper walkthroughs, see the guides and the narrative blog post in the source tree.

§Feature flags

FeatureDefaultEffect
serdeyesEnables Serialize/Deserialize impls in graph and async_trace.
const-reifynoEnables the [const_bridge] module. Adds 256 monomorphizations to compile time.
typenumnoBridge between nat and the typenum crate.
frunknoBridge between nat and frunk’s HList.
fullnoAll of the above.

Modules§

async_trace
Async computation tracing and step graph extraction.
context
Runtime-synthesized trait instances scoped to callbacks.
core
Core traits and types: Reflect, reify, Reified, RuntimeValue.
graph
Rc<RefCell<T>> graph reification and reconstruction.
nat
Type-level naturals (Z, S), booleans (True, False), and heterogeneous lists (HNil, HCons).