Skip to main content

Config

Derive Macro Config 

Source
#[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 - Use Default::default value if field is not present
  • default = $expr - Specifies expression used to initialize the value when it’s not present in config
  • default_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 value
      • replace - fully replaces with the new value
      • merge - merges object keys and concatenates arrays, merge is smart and will not merge values across different enums
    • Default behavior:
      • replace for all known value types
      • merge for unknown types
        • You will need to implement setty::combine::Combine for it to work for custom types
        • Config derive macro automatically implements it for you
        • If you don’t want any merging - simply override to use combine(replace)

§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