[][src]Struct justconfig::Config

pub struct Config { /* fields omitted */ }

Main struct representing a loaded configuration.

Implementations

impl Config[src]

pub fn add_source(&mut self, source: Box<dyn Source>)[src]

Add a configuration source to the configuration system.

Each configuration source must implement the Source trait. Multiple configuration sources can be added and are queried from first to last. The first configuration source that returns values for a configuration item will be used. All following configuration sources will be ignored for this configuration item.

Example

let mut conf = Config::default();

let mut source_1 = Defaults::default();
source_1.set(conf.root().push_all(&["myitem_A"]), "source_1", "source 1");
conf.add_source(source_1);

let mut source_2 = Defaults::default();
source_2.set(conf.root().push_all(&["myitem_A"]), "source_2", "source 2");
source_2.set(conf.root().push_all(&["myitem_B"]), "source_2", "source 2");
conf.add_source(source_2);

let value: String = conf.get(ConfPath::from(&["myitem_A"])).value().unwrap();
assert_eq!(value, "source_1");

let value: String = conf.get(ConfPath::from(&["myitem_B"])).value().unwrap();
assert_eq!(value, "source_2");

pub fn root(&self) -> ConfPath[src]

Convenience method to get a ConfPath instance.

Can be used to get a ConfPath instance to build configuration paths. If this ConfPath instance is used for all calls to the configuration library all configuration values can be enumerated. For details see ConfPath::children().

pub fn get(&self, key: ConfPath) -> Result<StringItem, ConfigError>[src]

Get the configuration value identified by the passed ConfPath.

This method is the root of every configuration pipeline. For usage examples see the crates documentation.

Trait Implementations

impl Default for Config[src]

pub fn default() -> Self[src]

Create a new configuration store.

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.