[−][src]Crate strum
Strum
Strum is a set of macros and traits for working with enums and strings easier in Rust.
The full version of the README can be found on Github.
Including Strum in Your Project
Import strum and strum_macros into your project by adding the following lines to your Cargo.toml. Strum_macros contains the macros needed to derive all the traits in Strum.
[dependencies]
strum = "0.17.0"
strum_macros = "0.17.0"
And add these lines to the root of your project, either lib.rs or main.rs.
// Strum contains all the trait definitions extern crate strum; #[macro_use] extern crate strum_macros;
Strum Macros
Strum has implemented the following macros:
Macro | Description |
---|---|
EnumString | Converts strings to enum variants based on their name |
Display | Converts enum variants to strings |
AsRefStr | Converts enum variants to &'static str |
IntoStaticStr | Implements From<MyEnum> for &'static str on an enum |
EnumVariantNames | Implements Strum::VariantNames which adds an associated constant VARIANTS which is an array of discriminant names |
EnumIter | Creates a new type that iterates of the variants of an enum. |
EnumProperty | Add custom properties to enum variants. |
EnumMessage | Add a verbose message to an enum variant. |
EnumDiscriminants | Generate a new type with only the discriminant names. |
EnumCount | Add a constant usize equal to the number of variants. |
Enums
ParseError | The ParseError enum is a collection of all the possible reasons an enum can fail to parse from a string. |
Traits
AsStaticRef | A cheap reference-to-reference conversion. Used to convert a value to a
reference value with |
EnumCount | A trait for capturing the number of variants in Enum. This trait can be autoderived by
|
EnumMessage | Associates additional pieces of information with an Enum. This can be
autoimplemented by deriving |
EnumProperty | EnumProperty is a trait that makes it possible to store additional information
with enum variants. This trait is designed to be used with the macro of the same
name in the |
IntoEnumIterator | This trait designates that an |
VariantNames | A trait for retrieving the names of each variant in Enum. This trait can
be autoderived by |