#[derive(Config)]
{
// Attributes available to this derive:
#[config]
#[serde]
#[schemars]
}
Expand description
Our main workhorse. Derives the attributes based on the set of enabled crate features.
§Field Attributes
These arguments can be specified in #[config(...)] field attribute:
default- UseDefault::defaultvalue if field is not presentdefault = $expr- Specifies expression used to initialize the value when it’s not present in configdefault_str = "$str"- Shorthand fordefault = "$str".parse().unwrap()combine(keep | replace | merge)- Allows overriding how values are combined across different config files- Possible values:
keep- keeps first seen valuereplace- fully replaces with the new valuemerge- merges object keys and concatenates arrays, merge is smart and will not merge values across different enums
- Default behavior:
replacefor all known value typesmergefor unknown types- You will need to implement
setty::combine::Combinefor it to work for custom types Configderive macro automatically implements it for you- If you don’t want any merging - simply override to use
combine(replace)
- You will need to implement
- Possible values:
§Interaction with other attributes
#[deprecated(since = "..", reason = "..")]attribute (and its other forms):- Will be propagated
- A
"deprecation": {"since": "..", "reason": ".."}will be added to JSON schema - Deprecation callback will be called if value is present in the config during loading
#[serde(...)]attribute will be propagated and can be used to override default behaviour (e.g.#[serde(tag = "type")])#[schemars(...)]attribute will be propagated