name-index 0.1.0

Library for accessing struct fields by name at runtime
Documentation
use name_index::{NameIndex, NameIndexCopy};

#[derive(Default, NameIndex)]
struct CoolStruct {
    #[index]
    a: bool,
    b: bool,
    c: bool,
    #[allow(dead_code)]
    other: String,
}

pub fn main() {
    let mut cool_struct = CoolStruct::default();
    cool_struct.b = true;

    let b = cool_struct.get("b").expect("'b' is a field of CoolStruct");
    cool_struct
        .set("c", b)
        .expect("'c' is a field of CoolStruct");

    cool_struct
        .fields_mut()
        .into_iter()
        .for_each(|(_, r)| *r = !*r);

    for (name, value) in cool_struct.fields() {
        println!("{}: {}", name, value);
    }
}