Skip to main content

setting_enum

Macro setting_enum 

Source
macro_rules! setting_enum {
    (
        $(#[$enum_meta:meta])*
        $vis:vis enum $name:ident: $setting:literal {
            $(
                $(#[$variant_meta:meta])*
                $variant:ident = $wire:literal
            ),+ $(,)?
        }
    ) => { ... };
}
Expand description

Declare a closed-set setting: an enum plus everything that follows from it.

See the module docs for the shape and the reasoning. The expansion derives Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize and Deserialize, and implements Setting, Display, FromStr and AsRef<str>.

The serde impls are written by hand rather than derived, for two reasons. The caller does not need serde in its own dependencies — the macro reaches it through this crate — and, more usefully, deserialising goes through Setting::parse, so the wire format cannot drift from the parser and a bad value in a config file gets the same message as a bad value in .env.