diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-03-31 15:28:14 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-03-31 15:28:14 +0200 |
commit | 0c77d287f9ac0ae2dd5a5691d4597a798ee4de3f (patch) | |
tree | 9663f19a3c40f2bdcce1892578e70a42bce9c24f /src | |
parent | e8dccf2850bc5ca7952cd267745ee3f2afa4d744 (diff) |
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 <mail@beyermatthias.de>
Diffstat (limited to 'src')
-rw-r--r-- | src/source.rs | 15 |
1 files 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<HashMap<String, Value>>; 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(()) } |