Skip to main content

Crate stratify

Crate stratify 

Source
Expand description

Layered configuration for Rust.

Stack configuration from files, environment variables and Azure App Configuration, merge them by declared precedence, and read the result as typed values.

use stratify::ConfigBuilder;

let store = ConfigBuilder::default()
    .json("config/base.json", 100)
    .yaml("config/override.yaml", 50)
    .env("APP_", "__", 10)
    .build()
    .await?;

let host = store.get_str("database.host");

§Precedence

Lower priority number wins. A source at priority 10 overrides one at 100. That is the opposite of treating the number as a weight, and it is deliberate: it lets a more specific source be added later without renumbering the ones already there.

Merging is deep. Nested objects combine key by key rather than the higher-precedence source replacing a whole subtree.

§Feature flags

  • azureAzureAppConfigSource, reading from Azure App Configuration. Off by default, because it brings in an HTTP stack that a file-and-environment user should not pay for.

Re-exports§

pub use builder::ConfigBuilder;
pub use error::ConfigError;
pub use source::Source;
pub use store::ConfigStore;

Modules§

builder
Fluent builder for assembling sources into a ConfigStore.
error
Error type returned by loading and lookup.
source
Built-in configuration sources and the Source trait.
store
The merged, cached configuration store.

Macros§

file_source
Macro to generate a file-based configuration source.