1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//! 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`](https://docs.rs/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
//!
//! | Module | Crate | Use it for |
//! |---|---|---|
//! | [`core`] | [`reify_reflect_core`] | The [`Reflect`](core::Reflect) trait, the [`reify`](core::reify) scoping function, the [`Reified`](core::Reified) branded token, and the [`RuntimeValue`](core::RuntimeValue) enum. |
//! | [`nat`] | [`reflect_nat`] | Peano naturals (`Z`/`S<N>`), type-level booleans, heterogeneous lists, with optional `frunk`/`typenum` bridges. |
//! | [`graph`] | [`reify_graph`] | Convert `Rc<RefCell<T>>` or `Arc<Mutex<T>>` graphs to and from a flat node+edge form, preserving sharing and cycles. |
//! | [`context`] | [`context_trait`] | Swap out `Ord`, `Hash`, `Display` (or any user-defined trait) for one block of code via `WithContext`. |
//! | [`async_trace`] | [`async_reify`] | Wrap futures to record poll events and turn them into an inspectable async step graph. |
//! | [`const_bridge`] (feature `const-reify`) | [`const_reify`](https://docs.rs/const-reify) | Dispatch 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.
//!
//! [guides]: https://github.com/joshburgess/reify-reflect/tree/main/docs/guides
//! [narrative blog post]: https://github.com/joshburgess/reify-reflect/blob/main/docs/blog-post.md
//!
//! # Feature flags
//!
//! | Feature | Default | Effect |
//! |---|---|---|
//! | `serde` | yes | Enables `Serialize`/`Deserialize` impls in [`graph`] and [`async_trace`]. |
//! | `const-reify` | no | Enables the [`const_bridge`] module. Adds 256 monomorphizations to compile time. |
//! | `typenum` | no | Bridge between [`nat`] and the `typenum` crate. |
//! | `frunk` | no | Bridge between [`nat`] and `frunk`'s HList. |
//! | `full` | no | All of the above. |
/// Core traits and types: [`Reflect`](reify_reflect_core::Reflect),
/// [`reify`](reify_reflect_core::reify), [`Reified`](reify_reflect_core::Reified),
/// [`RuntimeValue`](reify_reflect_core::RuntimeValue).
/// Type-level naturals ([`Z`](reflect_nat::Z), [`S`](reflect_nat::S)),
/// booleans ([`True`](reflect_nat::True), [`False`](reflect_nat::False)),
/// and heterogeneous lists ([`HNil`](reflect_nat::HNil), [`HCons`](reflect_nat::HCons)).
/// `Rc<RefCell<T>>` graph reification and reconstruction.
/// Runtime-synthesized trait instances scoped to callbacks.
/// Async computation tracing and step graph extraction.
/// Runtime-to-const-generic dispatch (requires `const-reify` feature).