summaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs
index 888d8cc..e6da482 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -151,6 +151,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()?;