Settings
Settings are the individual fields of a Config
struct or variants of a
Config
enum, and can be annotated with the optional #[setting]
attribute.
Attribute fields
The following fields are supported for the #[setting]
field/variant attribute:
default
- Sets the default value.env
(struct only) - Sets the environment variable to receive a value from.extend
(struct only) - Enables a configuration to extend other configs.merge
- Defines a function to use for merging values.nested
- Marks the field as using a nestedConfig
.parse_env
(struct only) - Parses the environment variable value using a function.required
- Marks the field as required. This is useful forOption
types that do not supportDefault
, but require a value.validate
- Defines a function to use for validating values.
And the following for serde compatibility:
alias
flatten
rename
skip
skip_deserializing
skip_serializing
Serde support
A handful of serde attribute fields are currently supported (above) and will apply a #[serde]
attribute to the partial implementation.
#![allow(unused)] fn main() { #[derive(Config)] struct Example { #[setting(rename = "type")] pub type_of: SomeEnum, } }
These values can also be applied using
#[serde]
, which is useful if you want to apply them to the main struct as well, and not just the partial struct.