Skip to content

Commit 0c77d28

Browse files
committed
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 <[email protected]>
1 parent e8dccf2 commit 0c77d28

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/source.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,15 @@ pub trait Source: Debug {
1414
fn collect(&self) -> Result<HashMap<String, Value>>;
1515

1616
fn collect_to(&self, cache: &mut Value) -> Result<()> {
17-
let props = match self.collect() {
18-
Ok(props) => props,
19-
Err(error) => {
20-
return Err(error);
21-
}
22-
};
23-
24-
for (key, val) in &props {
25-
match path::Expression::from_str(key) {
17+
self.collect()?
18+
.iter()
19+
.for_each(|(key, val)| match path::Expression::from_str(key) {
2620
// Set using the path
2721
Ok(expr) => expr.set(cache, val.clone()),
2822

2923
// Set diretly anyway
3024
_ => path::Expression::Identifier(key.clone()).set(cache, val.clone()),
31-
}
32-
}
25+
});
3326

3427
Ok(())
3528
}

0 commit comments

Comments
 (0)