summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-06-26 15:22:55 +0200
committerMatthias Beyer <mail@beyermatthias.de>2021-06-26 15:54:26 +0200
commit49f935abe56be4f85f06dab0363a6919ac4df813 (patch)
tree3574d5fa532dcf52ed085ade236d6de3260971b5
parent11602b0b046b0753541ca916a2ce1237f9d28e05 (diff)
Refactor: Extract setting of cache to helper fn
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/source.rs18
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()