[−][src]Struct justconfig::sources::defaults::Defaults
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
Auto Trait Implementations
impl !RefUnwindSafe for Defaults
[src]
impl !Send for Defaults
[src]
impl !Sync for Defaults
[src]
impl Unpin for Defaults
[src]
impl !UnwindSafe for Defaults
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,