summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/config.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs
index 888d8cc..1019061 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -78,6 +78,28 @@ impl Config {
self.refresh()
}
+ /// Merge in a configuration property source.
+ pub fn with_merged<T>(mut self, source: T) -> Result<Self>
+ where
+ T: 'static,
+ T: Source + Send + Sync,
+ {
+ match self.kind {
+ ConfigKind::Mutable {
+ ref mut sources, ..
+ } => {
+ sources.push(Box::new(source));
+ }
+
+ ConfigKind::Frozen => {
+ return Err(ConfigError::Frozen);
+ }
+ }
+
+ self.refresh()?;
+ Ok(self)
+ }
+
/// Refresh the configuration cache with fresh
/// data from added sources.
///
@@ -151,6 +173,18 @@ impl Config {
self.refresh()
}
+ pub fn set_once(&mut self, key: &str, value: Value) -> Result<()> {
+ let expr: path::Expression = key.parse()?;
+
+ // Traverse the cache using the path to (possibly) retrieve a value
+ if let Some(ref mut val) = expr.get_mut(&mut self.cache) {
+ **val = value;
+ } else {
+ expr.set(&mut self.cache, value);
+ }
+ Ok(())
+ }
+
pub fn get<'de, T: Deserialize<'de>>(&self, key: &str) -> Result<T> {
// Parse the key into a path expression
let expr: path::Expression = key.parse()?;