summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-03-14 08:58:40 +0100
committerMatthias Beyer <mail@beyermatthias.de>2021-03-14 08:58:40 +0100
commit05b04b8a9982154b1f0755c0b4e0eb2cb3d88235 (patch)
tree3320472f8bc6874f01660f6887d88c773cba1d22
parent887736dc67740e5316a892bfcb569f62d0fc45da (diff)
parentea25d5ff9858a7cc03477f31cb3140a43977e6fd (diff)
Merge branch 'add-setter'
-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()?;