summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-03-31 15:28:14 +0200
committerMatthias Beyer <mail@beyermatthias.de>2021-03-31 15:28:14 +0200
commit0c77d287f9ac0ae2dd5a5691d4597a798ee4de3f (patch)
tree9663f19a3c40f2bdcce1892578e70a42bce9c24f
parente8dccf2850bc5ca7952cd267745ee3f2afa4d744 (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>
-rw-r--r--src/source.rs15
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(())
}