From 49f935abe56be4f85f06dab0363a6919ac4df813 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 26 Jun 2021 15:22:55 +0200 Subject: Refactor: Extract setting of cache to helper fn Signed-off-by: Matthias Beyer --- src/source.rs | 18 +++++++++++------- 1 file 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 { fn clone(&self) -> Box { self.clone_into_box() -- cgit v1.2.3