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§

EnumDisplay
Derives Display for an unitary enum, which outputs the name of the variant.
EnumFromInner
Derives From<T> for each variant’s payload, assuming all variants are unary.
EnumFromStr
Derives FromStr for an unitary enum. It requires an exact match of the variant name.
EnumInnerAsTrait
Derives a method for an unary enum returning a borrowed pointer to the inner value, cast to a trait object.
IterVariantNames
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.
IterVariants
Derives iter_variants() for an unitary enum, which returns an iterator over the variants of the enum in lexical order.
NextVariant
Derives next_variant(&self) for an unitary enum, which returns the next variant, or None when called for the last.
PrevVariant
Derives prev_variant(&self) for an unitary enum, which returns the previous variant, or None when called for the first.

Structs§

ParseEnumError
The FromStr derived implementations error type.