pub struct Defaults { /* private fields */ }
Expand description
Implements the Defaults source.
Implementations
sourceimpl Defaults
impl Defaults
sourcepub fn default() -> Box<Self>
pub fn default() -> Box<Self>
Creates a new defaults source.
The created Defaults
instance does not contain any values.
See the defaults
module for more information.
sourcepub fn set(&mut self, key: ConfPath, value: &str, source: &str)
pub fn set(&mut self, key: ConfPath, value: &str, source: &str)
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.
sourcepub fn put(&mut self, key: ConfPath, value: &str, source: &str)
pub fn put(&mut self, key: ConfPath, value: &str, source: &str)
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
Auto Trait Implementations
impl !RefUnwindSafe for Defaults
impl !Send for Defaults
impl !Sync for Defaults
impl Unpin for Defaults
impl !UnwindSafe for Defaults
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