Struct justconfig::Config
source · [−]pub struct Config { /* private fields */ }
Expand description
Main struct representing a loaded configuration.
Implementations
sourceimpl Config
impl Config
sourcepub fn add_source(&mut self, source: Box<dyn Source>)
pub fn add_source(&mut self, source: Box<dyn Source>)
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");
sourcepub fn root(&self) -> ConfPath
pub fn root(&self) -> ConfPath
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()
.
sourcepub fn get(&self, key: ConfPath) -> Result<StringItem, ConfigError>
pub fn get(&self, key: ConfPath) -> Result<StringItem, ConfigError>
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
Auto Trait Implementations
impl !RefUnwindSafe for Config
impl !Send for Config
impl !Sync for Config
impl Unpin for Config
impl !UnwindSafe for Config
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more