grw_derive 0.1.0

Derive macros for the grw graph rewriting library
Documentation
  • Coverage
  • 0%
    0 out of 3 items documented0 out of 2 items with examples
  • Size
  • Source code size: 31.89 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 320.77 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 35s Average build duration of successful builds.
  • all releases: 35s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • grw-rs/grw_derive
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • grw-rs

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 introspectionfields() returns field names, types, and byte offsets at runtime
  • Layout hash — deterministic layout_hash() for binary compatibility checks (used by Graph::save/load)
  • Size/alignmentsize() and align() matching std::mem
use grw::Val;

#[derive(Val)]
struct Particle {
    x: f64,
    y: f64,
    mass: f32,
    active: bool,
}

// runtime field access
let fields = Particle::fields();
assert_eq!(fields[0].name, "x");
assert_eq!(fields.len(), 4);

// layout hash for persistence validation
let hash = Particle::layout_hash();
assert_ne!(hash, 0);

Supported field types: bool, i8i64, u8u64, f32, f64, String, nested Val structs, #[repr(u8)] enums.

Enums

#[derive(Val, Clone, Copy)]
#[repr(u8)]
enum Color { Red, Green, Blue }

// variants with discriminants are introspectable
let ft = Color::field_type();

#[grw::repl]

Attribute macro for impl blocks. Generates extern "C" wrappers and method metadata for REPL/JIT integration:

#[derive(Val)]
struct Point { x: f64, y: f64 }

#[grw::repl]
impl Point {
    fn distance(&self) -> f64 {
        (self.x * self.x + self.y * self.y).sqrt()
    }

    fn new(x: f64, y: f64) -> Self {
        Point { x, y }
    }
}

// methods are discoverable at runtime
let methods = Point::methods();
assert_eq!(methods[0].name, "distance");
assert!(!methods[0].is_static);

assert_eq!(methods[1].name, "new");
assert!(methods[1].is_static);

Supports:

  • &self methods returning scalars (bool, i8i64, u8u64, f32, f64)
  • Static methods (constructors, factories)
  • Multi-parameter methods
  • String return type (metadata only, fn_ptr is null — not callable via FFI)
  • &mut self methods are silently skipped

License

Licensed under either of

at your option.