Module smart_config::fallback
source · Expand description
Fallback Value
sources.
§Motivation and use cases
Some configuration params may be sourced from places that do not fit well into the hierarchical config schema.
For example, a config param with logging directives may want to read from a RUST_LOG
env var, regardless of where
the param is placed in the hierarchy. It is possible to manually move raw config values around, it may get unmaintainable
for large configs.
Fallbacks provide a more sound approach: declare the fallback config sources as a part of the DescribeConfig
derive macro. In this way, fallbacks are documented (being a part of the config metadata)
and do not require splitting logic between config declaration and preparing config sources.
Fallbacks should be used sparingly, since they make it more difficult to reason about configs due to their non-local nature.
§Features and limitations
- By design, fallbacks are location-independent. E.g., an
Env
fallback will always read from the same env var, regardless of where the param containing it is placed (including the case when it has multiple copies!). - Fallbacks always have lower priority than all other config sources.
Structs§
- Gets a string value from the specified env variable.
- Custom fallback value provider.
Traits§
- Fallback source of a configuration param.