[][src]Struct justconfig::sources::defaults::Defaults

pub struct Defaults { /* fields omitted */ }

Implements the Defaults source.

Implementations

impl Defaults[src]

pub fn default() -> Box<Self>[src]

Creates a new defaults source.

The created Defaults instance does not contain any values.

See the defaults module for more information.

pub fn empty(&mut self, key: ConfPath)[src]

Clear all values for the given key.

pub fn set(&mut self, key: ConfPath, value: &str, source: &str)[src]

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.

pub fn put(&mut self, key: ConfPath, value: &str, source: &str)[src]

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

impl Source for Defaults[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.