Crate gratte_macros

Source
Expand description

§gratte (a strum fork)

gratte is a fork of strum. It defines a set of macros and traits for working with enums and strings easier in Rust.

This crate only contains derive macros for use with the gratte crate. The macros provided by this crate are available by enabling the derive feature in the aforementioned gratte crate (which it is by default).

Derive Macros§

AsRefStr
Converts enum variants to &'a str, where 'a is the lifetime of the input enum reference.
Display
Converts enum variants to strings.
EnumCount
Add a constant usize equal to the number of variants.
EnumDiscriminants
Generate a new type with only the discriminant names.
EnumIs
Generated is_*() methods for each variant. E.g. Color.is_red().
EnumIter
Creates a new type that iterates over the variants of an enum.
EnumMessage
Add a verbose message to an enum variant.
EnumProperty
Add custom properties to enum variants.
EnumString
Converts strings to enum variants based on their name.
EnumTryAs
Generated try_as_*() methods for all tuple-style variants. E.g. Message.try_as_write().
FromRepr
Add a function to enum that allows accessing variants by its discriminant
IntoStaticStr
Implements From<MyEnum> for &'static str on an enum.
VariantArray
Adds a 'static slice with all the Enum’s variants.
VariantNames
Implements gratte::VariantNames which adds an associated constant VARIANTS which is a 'static slice of discriminant names.