#reflection #generate #type #counter #invade

macro invade_derive

A library to reflect on Rust types and generate code

6 releases

0.0.6 Feb 14, 2024
0.0.5 Feb 14, 2024

#88 in #reflection


Used in invade

MIT/Apache

7KB
115 lines

invade

Setup

cargo add invade

Usage

use invade::invade;

#[invade]
struct Counter {
    count: u32,
}

#[invade]
impl Counter {
    fn inc(&mut self) {
        self.count += 1;
    }
}

fn main() {
    let mut counter = Counter { count: 0 };
  
    println!("count: {:?}", counter.invade_get::<u32>("count"));

    counter.invade_set("count", 1_u32);

    assert_eq!(counter.count, 1);

    counter.invade_call("inc", vec![]);

    assert_eq!(counter.count, 2);
}

Dependencies

~275–730KB
~17K SLoC