pub struct Defaults { /* private fields */ }
Expand description

Implements the Defaults source.

Implementations

Creates a new defaults source.

The created Defaults instance does not contain any values.

See the defaults module for more information.

Clear all values for the given key.

Set the value of this key

Sets the value of the given key to the passed value. All previously set values are discarded.

The source parameter specifies a string that is used to identify the source for this configuration information in error messages.

See put for an example.

Add a value to the configuration values of this key

Adds a value to the configuration values of the given key. This can be used to add multiple values for a configuration item.

If you want to clear all previously set values instead of adding the value to the list of configuration values use set.

The source parameter specifies a string that is used to identify the source for this configuration information in error messages.

Example
use justconfig::Config;
use justconfig::ConfPath;
use justconfig::item::ValueExtractor;
use justconfig::sources::defaults::Defaults;

let mut conf = Config::default();
let mut defaults = Defaults::default();
 
defaults.set(ConfPath::from(&["Destination"]), "/tmp", "Default destination directory");
defaults.set(ConfPath::from(&["Sources"]), "/srv/source/a", "Default source directory A");
defaults.put(ConfPath::from(&["Sources"]), "/srv/source/b", "Default source directory B");
 
conf.add_source(defaults);

let destination: String = conf.get(ConfPath::from(&["Destination"])).value().unwrap();
assert_eq!(destination, "/tmp");
 
let sources: Vec<String> = conf.get(ConfPath::from(&["Sources"])).values(1..).unwrap();
assert_eq!(sources, ["/srv/source/a", "/srv/source/b"]);

Trait Implementations

Get a configuration option. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.