Expand description
This crate provides several macros for deriving some useful methods for unitary enums (i.e. enums where variants do not have payloads) and unary enums.
§Feature flags
std
(enabled by default) — disable to make the library#![no_std]
.
§Using with and without macro_attr!
All of the macros are designed to be used with the
macro-attr-2018
crate,
though they can be used independent of it. The following:
macro_attr! {
#[derive(Copy, Clone, Debug, IterVariants!(Vars))]
enum ItAintRight { BabeNo, NoNo, BoyBoy }
}
can also be written as
#[derive(Copy, Clone, Debug)]
enum ItAintRight { BabeNo, NoNo, BoyBoy }
IterVariants! { (Vars) enum ItAintRight { BabeNo, NoNo, BoyBoy } }
Macros§
- Enum
Display - Derives
Display
for an unitary enum, which outputs the name of the variant. - Enum
From Inner - Derives
From<T>
for each variant’s payload, assuming all variants are unary. - Enum
From Str - Derives
FromStr
for an unitary enum. It requires an exact match of the variant name. - Enum
Inner AsTrait - Derives a method for an unary enum returning a borrowed pointer to the inner value, cast to a trait object.
- Iter
Variant Names - Derives
iter_variant_names()
for an unitary enum, which returns an iterator over the string names of the variants of the enum in lexical order. - Iter
Variants - Derives
iter_variants()
for an unitary enum, which returns an iterator over the variants of the enum in lexical order. - Next
Variant - Derives
next_variant(&self)
for an unitary enum, which returns the next variant, orNone
when called for the last. - Prev
Variant - Derives
prev_variant(&self)
for an unitary enum, which returns the previous variant, orNone
when called for the first.
Structs§
- Parse
Enum Error - The
FromStr
derived implementations error type.