Skip to content

Commit 356f173

Browse files
Merge pull request #172 from matthiasbeyer/add-setter
Add setter for setting config value once
2 parents 66e3f7d + 6ab07dd commit 356f173

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/config.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,18 @@ impl Config {
173173
self.refresh()
174174
}
175175

176+
pub fn set_once(&mut self, key: &str, value: Value) -> Result<()> {
177+
let expr: path::Expression = key.parse()?;
178+
179+
// Traverse the cache using the path to (possibly) retrieve a value
180+
if let Some(ref mut val) = expr.get_mut(&mut self.cache) {
181+
**val = value;
182+
} else {
183+
expr.set(&mut self.cache, value);
184+
}
185+
Ok(())
186+
}
187+
176188
pub fn get<'de, T: Deserialize<'de>>(&self, key: &str) -> Result<T> {
177189
// Parse the key into a path expression
178190
let expr: path::Expression = key.parse()?;

0 commit comments

Comments
 (0)