Crates.io | struct_field |
lib.rs | struct_field |
version | 0.1.6 |
source | src |
created_at | 2021-08-14 05:38:57.079163 |
updated_at | 2022-03-20 11:28:04.118224 |
description | Derive macros for generating each field in a struct |
homepage | |
repository | https://github.com/rise0chen/struct_field |
max_upload_size | |
id | 435967 |
size | 8,540 |
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,
}
}
}
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>,
}