Expand description
§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.23"
strum_macros = "0.23"
# You can also access strum_macros exports directly through strum using the "derive" feature
strum = { version = "0.23", features = ["derive"] }Modules§
- additional_
attributes - Documentation for Additional Attributes
Enums§
- Parse
Error - The ParseError enum is a collection of all the possible reasons an enum can fail to parse from a string.
Traits§
- AsStatic
Ref Deprecated - A cheap reference-to-reference conversion. Used to convert a value to a
reference value with
'staticlifetime within generic code. - Enum
Count - A trait for capturing the number of variants in Enum. This trait can be autoderived by
strum_macros. - Enum
Message - Associates additional pieces of information with an Enum. This can be
autoimplemented by deriving
EnumMessageand annotating your variants with `#[strum(message=“…”)]. - Enum
Property - 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
strum_macroscrate. Currently, the only string literals are supported in attributes, the other methods will be implemented as additional attribute types become stabilized. - Into
Enum Iterator - This trait designates that an
Enumcan be iterated over. It can be auto generated usingstrum_macroson your behalf. - Variant
Names - A trait for retrieving the names of each variant in Enum. This trait can
be autoderived by
strum_macros.
Derive Macros§
- AsRef
Str derive - Converts enum variants to
&'static str. - AsStatic
Str derive - Display
derive - Converts enum variants to strings.
- Enum
Count derive - Add a constant
usizeequal to the number of variants. - Enum
Discriminants derive - Generate a new type with only the discriminant names.
- Enum
Iter derive - Creates a new type that iterates of the variants of an enum.
- Enum
Message derive - Add a verbose message to an enum variant.
- Enum
Property derive - Add custom properties to enum variants.
- Enum
String derive - Converts strings to enum variants based on their name.
- Enum
Variant Names derive - Implements Strum::VariantNames which adds an associated constant
VARIANTSwhich is an array of discriminant names. - From
Repr derive - Add a function to enum that allows accessing variants by its discriminant
- Into
Static Str derive - Implements
From<MyEnum> for &'static stron an enum. - ToString
derive - implements
std::string::ToStringon en enum