[][src]Module justconfig::sources::env

Environment source

The environment source supplies environment variables to the configuration system. By being its own source it can be ordered before or after other sources. This way environment variables can override configuration settings or can be used as a fallback.

The environment source uses a mapping to translate the names of environment variables into configuration paths. This mapping is passed to the new method. Environment variables not present within this mapping are inaccessible by the configuration system. Adding a mapping for an environment variable does not make sure it really exists.

Example

use justconfig::Config;
use justconfig::ConfPath;
use std::ffi::OsStr;
use justconfig::item::ValueExtractor;
use justconfig::sources::env::Env;

let mut conf = Config::default();

conf.add_source(Env::new(&[
  (ConfPath::from(&["Path"]), OsStr::new("PATH")),
  (ConfPath::from(&["HomeDir"]), OsStr::new("HOME"))
]));

// Read the path from the environment
let path: String = conf.get(ConfPath::from(&["Path"])).value().unwrap();

Structs

Env

Implements the environment source.