diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-06-26 15:22:55 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-06-26 15:54:26 +0200 |
commit | 49f935abe56be4f85f06dab0363a6919ac4df813 (patch) | |
tree | 3574d5fa532dcf52ed085ade236d6de3260971b5 | |
parent | 11602b0b046b0753541ca916a2ce1237f9d28e05 (diff) |
Refactor: Extract setting of cache to helper fn
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | src/source.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/source.rs b/src/source.rs index dc5f3b5..bf2ed87 100644 --- a/src/source.rs +++ b/src/source.rs @@ -17,18 +17,22 @@ pub trait Source: Debug { fn collect_to(&self, cache: &mut Value) -> Result<()> { self.collect()? .iter() - .for_each(|(key, val)| match path::Expression::from_str(key) { - // Set using the path - Ok(expr) => expr.set(cache, val.clone()), - - // Set diretly anyway - _ => path::Expression::Identifier(key.clone()).set(cache, val.clone()), - }); + .for_each(|(key, val)| set_value(cache, key, val)); Ok(()) } } +fn set_value(cache: &mut Value, key: &String, value: &Value) { + match path::Expression::from_str(key) { + // Set using the path + Ok(expr) => expr.set(cache, value.clone()), + + // Set diretly anyway + _ => path::Expression::Identifier(key.clone()).set(cache, value.clone()), + } +} + impl Clone for Box<dyn Source + Send + Sync> { fn clone(&self) -> Box<dyn Source + Send + Sync> { self.clone_into_box() |