[][src]Macro feattle::feattle_enum

macro_rules! feattle_enum {
    (
        $(#[$enum_meta:meta])*
        $visibility:vis enum $name:ident {
            $(
                $(#[$variant_meta:meta])*
                $variant:ident
            ),+ $(,)?
        }
    ) => { ... };
}

Define an enum that can be used as a type for a feattle

The generated enum will have these standard traits: Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, FromStr, Display. And mainly, it will implement crate::FeattleStringValue so that it can be used a feattle type.

Only enums whose variants do not carry any extra information are supported.

Examples

In the simplest form:

use feattle_core::feattle_enum;

feattle_enum! {
    enum Colors { Red, Green, Blue }
}

However, it also works with other visibility keywords and additional attributes on the enum itself or its variants. Those attributes will not be modified by this lib, allowing composition with other libs. For example, you can also make the enum Serialize:

use feattle_core::feattle_enum;
use serde::Serialize;

feattle_enum! {
    #[derive(Serialize)]
    pub(crate) enum Colors {
        #[serde(rename = "R")]
        Red,
        #[serde(rename = "G")]
        Green,
        #[serde(rename = "B")]
        Blue,
    }
}