reify-reflect 0.1.0

Unified reification and reflection ecosystem for Rust
Documentation

reify-reflect

CI Crates.io Docs.rs License: MIT OR Apache-2.0 MSRV

Unified reification and reflection ecosystem for Rust.

Crates

Crate Description
reify-reflect-core Reflect trait, reify function, Reified token, RuntimeValue enum
reflect-nat Type-level naturals (Z/S<N>), booleans, HLists, optional frunk/typenum bridges
reflect-derive #[derive(Reflect)] proc macro
reify-graph Rc<RefCell<T>> and Arc<Mutex<T>> graph reification and reconstruction
context-trait Runtime-synthesized trait instances (Ord, Hash, Display)
async-reify Async computation step graph extraction
async-reify-macros #[trace_async] attribute proc macro for async-reify
const-reify Runtime-to-const-generic dispatch via match-table
const-reify-derive #[reifiable] proc macro that generates const-generic dispatch tables

Quick Start

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));

Derive Reflect for structs

use reflect_derive::Reflect;
use reify_reflect_core::{Reflect, RuntimeValue};

#[derive(Reflect)]
struct Config {
    x: S<S<Z>>,        // reflects to Nat(2)
    #[reflect(skip)]
    _internal: String,  // skipped
}

Reify pointer graphs

use reify_graph::{reify_graph, reflect_graph};

fn round_trip(root: Rc<RefCell<Node>>) -> Result<Rc<RefCell<Node>>, serde_json::Error> {
    let graph = reify_graph(root, |n| n.children.clone());
    let json = serde_json::to_string(&graph)?;
    let restored = serde_json::from_str(&json)?;
    Ok(reflect_graph(restored, |n, kids| n.children = kids))
}

Custom trait instances

use context_trait::{with_ord, WithContext, OrdContext};

with_ord!(items, |a: &Item, b: &Item| a.score.cmp(&b.score),
    |wrapped: &[WithContext<Item, OrdContext<Item>>]| {
        let mut sorted = wrapped.to_vec();
        sorted.sort();
    }
);

Trace async workflows

use async_reify::{TracedFuture, reify_execution, to_dot};

let (result, trace) = TracedFuture::run(my_async_fn()).await;
let graph = reify_execution(trace.events);
println!("{}", to_dot(&graph));

Runtime-to-const-generic dispatch

use const_reify::{reify_const, HasModulus};

let result = reify_const(42, |m| m.modulus() * 2);
assert_eq!(result, 84);

Features

Feature Default Description
serde yes Serialization for reify-graph and async-reify
const-reify no Runtime-to-const-generic dispatch (adds compile time)
full no All features

Documentation

  • cargo doc --features full --no-deps --open
  • Design docs in docs/, one per phase

Benchmarks

cargo bench --features full

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.