Skip to main content

Crate provcfg

Crate provcfg 

Source
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§

sources
Built-in Source implementations, each behind a feature:

Structs§

Config
A builder that collects Sources in priority order, then merges them.
DefaultsSource
The synthetic Source for the compiled-in defaults layer.
Value
A typed value together with the Source that supplied it. One entry of a ValueHistory.
ValueHistory
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::build and the add_*_file helpers.

Traits§

Provenance
Implemented by every generated *Prov struct.
Source
A named origin of raw configuration data.

Functions§

defaults_source
Shared SourceArc handle for the DefaultsSource layer.
deserialize_env_list
serde deserialize_with helper for Vec<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§

SourceArc
Shared, thread-safe handle to a Source, stored throughout the value-history graph.

Derive Macros§

ClapArgs
Re-export of the ClapArgs derive from the optional provcfg-clap integration. Enabled via the clap-derive feature. Generates a sibling <Name>Args clap-compatible struct plus a From<&<Name>Args> for <Name>Partial impl. Intended to be derived alongside provcfg::Configurable.
Configurable
Derive macro that turns a plain config struct into a provenance-tracking one.