From 0c77d287f9ac0ae2dd5a5691d4597a798ee4de3f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 31 Mar 2021 15:28:14 +0200 Subject: Simplify implementation This patch simplifies the Source::collect_to() default implementation by making use of the ? operator as well as the std::iter API. Signed-off-by: Matthias Beyer --- src/source.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/source.rs b/src/source.rs index 4d1ba53..8fb4ae3 100644 --- a/src/source.rs +++ b/src/source.rs @@ -14,22 +14,15 @@ pub trait Source: Debug { fn collect(&self) -> Result>; fn collect_to(&self, cache: &mut Value) -> Result<()> { - let props = match self.collect() { - Ok(props) => props, - Err(error) => { - return Err(error); - } - }; - - for (key, val) in &props { - match path::Expression::from_str(key) { + 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()), - } - } + }); Ok(()) } -- cgit v1.2.3