EnumUpdate

Derive Macro EnumUpdate 

Source
#[derive(EnumUpdate)]
{
    // Attributes available to this derive:
    #[variant_group]
    #[enum_update]
}
Expand description

Generates an enum representing updates to a given struct. See the README.md for an overview.

The EnumUpdate macro works by creating a list of “variant groups” with each group representing a modification to the state struct. By default, a variant group is constructed for each struct member. An enum variant is generated for each variant group containing all changes for fields in that group.

§Available attributes:

§variant_group

Specifies that a field should belong to an extra group.

#[derive(EnumUpdate)]
pub struct TimeSeriesData {
    #[variant_group(RecordOne)]
    time: u32,
    #[variant_group(RecordOne)]
    value_one: u32,
    #[variant_group]
    value_two: u32
}

will generate

pub enum TimeSeriesDataUpdate {
    RecordOne {
        time: u32,
        value_one: u32,
    },
    ValueTwo { value_two: u32 },
}

§enum_update

Passes on any provided attributes to the generated enum.

#[derive(EnumUpdate)]
#[enum_update(derive(Debug))]
pub struct State {
    #[variant_group]
    value: u32
}

will generate

#[derive(Debug)]
pub enum StateUpdate {
    Value { value: u32 }
}