Luro02 / shorthand

A proc-macro to derive getter, setter and mut getter for structs in rust.
Apache License 2.0
6 stars 0 forks source link

derive shorthand for enum #21

Open Luro02 opened 4 years ago

Luro02 commented 4 years ago
enum Example {
    Variant1 {
        field: usize,
    },
    Variant2 {
        field: usize,
    },
}

impl Example {
    pub fn set_field(&mut self, value: usize) -> &mut Self {
        match &mut self {
            Self::Variant1 { field } | Self::Variant2 { field } => {
                field = value;
            }
        }
        self
    }
}