grw_derive
Procedural macros for the GRW graph rewriting library.
This crate provides two macros used by grw for runtime type introspection and REPL integration. It is not intended to be used directly — it is re-exported through the grw crate.
#[derive(Val)]
Derives the Val trait on structs and #[repr(u8)] enums, providing:
- Field introspection —
fields()returns field names, types, and byte offsets at runtime - Layout hash — deterministic
layout_hash()for binary compatibility checks (used byGraph::save/load) - Size/alignment —
size()andalign()matchingstd::mem
use Val;
// runtime field access
let fields = fields;
assert_eq!;
assert_eq!;
// layout hash for persistence validation
let hash = layout_hash;
assert_ne!;
Supported field types: bool, i8–i64, u8–u64, f32, f64, String, nested Val structs, #[repr(u8)] enums.
Enums
// variants with discriminants are introspectable
let ft = field_type;
#[grw::repl]
Attribute macro for impl blocks. Generates extern "C" wrappers and method metadata for REPL/JIT integration:
// methods are discoverable at runtime
let methods = methods;
assert_eq!;
assert!;
assert_eq!;
assert!;
Supports:
&selfmethods returning scalars (bool,i8–i64,u8–u64,f32,f64)- Static methods (constructors, factories)
- Multi-parameter methods
Stringreturn type (metadata only, fn_ptr is null — not callable via FFI)&mut selfmethods are silently skipped
License
Licensed under either of
at your option.