Crate strum_macros
source ·Expand description
Strum
Strum is a set of macros and traits for working with enums and strings easier in Rust.
Derive Macros
- Converts enum variants to
&'static str. - Converts enum variants to strings.
- Add a constant
usizeequal to the number of variants. - Generate a new type with only the discriminant names.
- Generated
is_*()methods for each variant. E.g.Color.is_red(). - Creates a new type that iterates of the variants of an enum.
- Add a verbose message to an enum variant.
- Add custom properties to enum variants.
- Converts strings to enum variants based on their name.
- Creates a new type that maps all the variants of an enum to another generic value.
- Generated
try_as_*()methods for all tuple-style variants. E.g.Message.try_as_write(). - Add a function to enum that allows accessing variants by its discriminant
- Implements
From<MyEnum> for &'static stron an enum. - Adds a static array with all of the Enum’s variants.
- Implements
Strum::VariantNameswhich adds an associated constantVARIANTSwhich is an array of discriminant names.