[][src]Module justconfig::sources::defaults

Source supplying static defaults

The 'Defaults' source supplies static values for configuration items. It can be used to add static configuration values as defaults or to overwrite values originating from a configuration file with values supplied at the command line.

Multiple Defaults sources can be added to the same Config instance. The sources are queried from first to last. Depending on the order the Defaults source can supply defaults or overwrite values.

+------------+---------------------+
| Defaults   | from command line   |
+------------+---------------------+
| ConfigText | to read config file |
+------------+---------------------+
| Defaults   | as defaults         |
+------------+---------------------+

Example

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

let mut conf = Config::default();
let mut defaults = Defaults::default();
let mut env = Env::new(&[(ConfPath::from(&["Workdir"]), OsStr::new("WORKDIR"))]);
 
defaults.set(ConfPath::from(&["Workdir"]), "/tmp", "Default Workdir /tmp");
 
conf.add_source(defaults);
conf.add_source(env);

// If the environment variabel `WORKDIR` ist not set use `/tmp´ as a defualt.
let path: String = conf.get(ConfPath::from(&["Workdir"])).value().unwrap();
assert_eq!(path, "/tmp");

Structs

DefaultSourceLocation

Source location for the Defaults configuration source.

Defaults

Implements the Defaults source.