struct_field

Crates.iostruct_field
lib.rsstruct_field
version0.1.6
sourcesrc
created_at2021-08-14 05:38:57.079163
updated_at2022-03-20 11:28:04.118224
descriptionDerive macros for generating each field in a struct
homepage
repositoryhttps://github.com/rise0chen/struct_field
max_upload_size
id435967
size8,540
Rise Chen (rise0chen)

documentation

https://docs.rs/struct_field

README

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>,
}
Commit count: 8

cargo fmt