Extract

Derive Macro Extract 

Source
#[derive(Extract)]
{
    // Attributes available to this derive:
    #[extract]
}
Expand description

Constructs enums by extracting the set of variants from the original enum.

§Example

#[derive(Extract)]
#[extract(arg(ident = ExtractMercury, variants(Mercury)))]
pub enum Planet {
    Mercury,
    Venus,
    Earth,
    Mars,
}

The above code will generate the following enum:

pub enum ExtractMercury {
    Mercury,
}

§Attributes

#[derive(Extract)]
#[extract(
    [forward_attrs(<ATTR, ...> | not(<ATTR, ...>))], // Forward specific attributes to all generated enums
    arg(
        ident = <IDENT>, // The identifier of the generated enum
        variants(<VARIANT>, ...), // The variants to extract from the original enum
        [derive(<DERIVE>, ...)], // Derive attributes for the generated enum
        [forward_attrs(<ATTR, ...> | not(<ATTR, ...>))], // Forward specific attributes to the generated enum
            // If given, will override the container level `forward_attrs`
    ), ...
)]
pub enum BasedEnum {
    #[extract(
        [forward_attrs(<ATTR, ...> | not(<ATTR, ...>))], // Forward specific attributes to the generated variant
            // If given, will override the container level and arg level `forward_attrs`
    )]
    variant: VariantType,
}