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:
- Environment variables
- String literals in well-known formats
- Another
Configinstance - Files in well known formats and custom ones defined with
Formattrait - Manual, programmatic overrides
Additionally, Config supports:
- Live watching and re-reading of configuration files
- Deep access into the merged configuration via a path syntax
- Deserialization via
serdeof 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§
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.
- File
Source File - Describes a file sourced from a file
- File
Source String - Describes a file sourced from a string
- Value
- A configuration value.
Enums§
- Case
- Defines the type of casing a string can be.
- Config
Error - Represents all possible errors that can occur when working with configuration.
- File
Format - File formats provided by the library.
- Value
Kind - Underlying kind of the configuration value.
Traits§
- Async
Source - Describes a generic source of configuration properties capable of using an async runtime.
- File
Source - Describes where the
Fileis sourced - File
Stored Format - An extension of
Formattrait. - Format
- Describes a format of configuration source data
- Source
- Describes a generic source of configuration properties.