Crate enum_derive_2018
source ·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§
- Derives
Display
for an unitary enum, which outputs the name of the variant. - Derives
From<T>
for each variant’s payload, assuming all variants are unary. - Derives
FromStr
for an unitary enum. It requires an exact match of the variant name. - Derives a method for an unary enum returning a borrowed pointer to the inner value, cast to a trait object.
- 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. - Derives
iter_variants()
for an unitary enum, which returns an iterator over the variants of the enum in lexical order. - Derives
next_variant(&self)
for an unitary enum, which returns the next variant, orNone
when called for the last. - Derives
prev_variant(&self)
for an unitary enum, which returns the previous variant, orNone
when called for the first.
Structs§
- The
FromStr
derived implementations error type.