Crate config

Source
Expand description

Config organizes hierarchical or layered configurations for Rust applications.

Config lets you set a set of default parameters and then extend them via merging in configuration from a variety of sources:

Additionally, Config supports:

  • Live watching and re-reading of configuration files
  • Deep access into the merged configuration via a path syntax
  • Deserialization via serde of the configuration or any subset defined via a path

§Example

use std::collections::HashMap;

use config::Config;

fn main() {
    let settings = Config::builder()
        // Add in `./Settings.toml`
        .add_source(config::File::with_name("examples/simple/Settings"))
        // Add in settings from the environment (with a prefix of APP)
        // Eg.. `APP_DEBUG=1 ./target/app` would set the `debug` key
        .add_source(config::Environment::with_prefix("APP"))
        .build()
        .unwrap();

    // Print out our settings (as a HashMap)
    println!(
        "{:?}",
        settings
            .try_deserialize::<HashMap<String, String>>()
            .unwrap()
    );
}

See more examples for general usage information.

Re-exports§

pub use crate::builder::ConfigBuilder;

Modules§

builder

Structs§

Config
A prioritized configuration repository.
Environment
An environment source collects a dictionary of environment variables values into a hierarchical config Value type. We have to be aware how the config tree is created from the environment dictionary, therefore we are mindful about prefixes for the environment keys, level separators, encoding form (kebab, snake case) etc.
File
A configuration source backed up by a file.
FileSourceFile
Describes a file sourced from a file
FileSourceString
Describes a file sourced from a string
Value
A configuration value.

Enums§

Caseconvert-case
Defines the type of casing a string can be.
ConfigError
Represents all possible errors that can occur when working with configuration.
FileFormat
File formats provided by the library.
ValueKind
Underlying kind of the configuration value.

Traits§

AsyncSourceasync
Describes a generic source of configuration properties capable of using an async runtime.
FileSource
Describes where the File is sourced
FileStoredFormat
An extension of Format trait.
Format
Describes a format of configuration source data
Source
Describes a generic source of configuration properties.

Type Aliases§

Map
The backing store for Config