7 releases
0.1.6 | Mar 20, 2022 |
---|---|
0.1.5 | Mar 7, 2022 |
0.1.4 | Aug 19, 2021 |
#109 in #struct-fields
7KB
124 lines
struct_field
Provides StructField
derive macro.
#[derive(StructField)]
struct SomeStruct {
field_one: i32,
field_two: Vec<bool>,
}
generates
enum SomeStructField {
field_one(i32),
field_two(Vec<bool>),
}
impl SomeStruct {
pub fn update_field(&mut self, field: SomeStructField) {
match field {
SomeStructField::field_one(field_one) => self.field_one = field_one,
SomeStructField::field_two(field_two) => self.field_two = field_two,
}
}
}
Usage
Use the StructField
derive macro.
#[derive(StructField)]
struct SomeStruct {
field_one: i32,
field_two: Vec<bool>,
}
Use #[struct_field(skip)]
to skip fields.
#[derive(StructField)]
struct SomeStruct {
field_one: i32,
#[struct_field(skip)]
field_two: Vec<bool>,
}
Dependencies
~1.5MB
~37K SLoC