Expand description
A Rust config loader that tracks where each value came from.
provcfg layers configuration sources (compiled-in defaults, files,
environment variables, CLI flags) into one struct, and keeps the
provenance of every leaf field: which source set the active value, and
which earlier sources it overrode.
Derive Configurable on a plain config struct. Config::build returns
a companion *Prov struct whose every leaf is a ValueHistory: the value
paired with the Source it came from.
use provcfg::{Category, Config, Configurable};
#[derive(Configurable, serde::Deserialize, Clone, Default)]
struct Settings {
host: String,
port: u16,
}
// The environment has `APP_HOST=db.internal` set, but no `APP_PORT`.
let settings = Config::new()
.add_env("APP")
.build::<SettingsProv>()
.unwrap();
// `host` was set by the environment source.
assert_eq!(settings.host.value(), "db.internal");
assert_eq!(settings.host.source().category(), Category::Env);
// `port` was set by nobody, so it falls back to the compiled-in default.
assert_eq!(settings.port.value(), &0);
assert_eq!(settings.port.source().category(), Category::Default);§When this crate is useful
Use provcfg when you need to know which source set each value: rendering a
settings page that labels fields by origin, or debugging a value’s history
across layered sources. For plain merged-config loading,
config is the standard choice and less
ceremony.
Re-exports§
pub use erased_serde;
Modules§
Structs§
- Config
- A builder that collects
Sources in priority order, then merges them. - Defaults
Source - The synthetic
Sourcefor the compiled-in defaults layer. - Value
- A typed value together with the
Sourcethat supplied it. One entry of aValueHistory. - Value
History - The ordered history of values a single config leaf received.
Enums§
- Category
- Which kind of source contributed a value.
- Error
- The error type returned by
Config::buildand theadd_*_filehelpers.
Traits§
- Provenance
- Implemented by every generated
*Provstruct. - Source
- A named origin of raw configuration data.
Functions§
- defaults_
source - Shared
SourceArchandle for theDefaultsSourcelayer. - deserialize_
env_ list serdedeserialize_withhelper forVec<String>leaves that accepts either a real array (TOML/JSON arrays) or a comma-separated string (the form env vars and bare CLI flags use).
Type Aliases§
Derive Macros§
- Clap
Args - Re-export of the
ClapArgsderive from the optionalprovcfg-clapintegration. Enabled via theclap-derivefeature. Generates a sibling<Name>Argsclap-compatible struct plus aFrom<&<Name>Args> for <Name>Partialimpl. Intended to be derived alongsideprovcfg::Configurable. - Configurable
- Derive macro that turns a plain config struct into a provenance-tracking one.