Skip to content

Commit 49f935a

Browse files
committed
Refactor: Extract setting of cache to helper fn
Signed-off-by: Matthias Beyer <[email protected]>
1 parent 11602b0 commit 49f935a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/source.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,22 @@ pub trait Source: Debug {
1717
fn collect_to(&self, cache: &mut Value) -> Result<()> {
1818
self.collect()?
1919
.iter()
20-
.for_each(|(key, val)| match path::Expression::from_str(key) {
21-
// Set using the path
22-
Ok(expr) => expr.set(cache, val.clone()),
23-
24-
// Set diretly anyway
25-
_ => path::Expression::Identifier(key.clone()).set(cache, val.clone()),
26-
});
20+
.for_each(|(key, val)| set_value(cache, key, val));
2721

2822
Ok(())
2923
}
3024
}
3125

26+
fn set_value(cache: &mut Value, key: &String, value: &Value) {
27+
match path::Expression::from_str(key) {
28+
// Set using the path
29+
Ok(expr) => expr.set(cache, value.clone()),
30+
31+
// Set diretly anyway
32+
_ => path::Expression::Identifier(key.clone()).set(cache, value.clone()),
33+
}
34+
}
35+
3236
impl Clone for Box<dyn Source + Send + Sync> {
3337
fn clone(&self) -> Box<dyn Source + Send + Sync> {
3438
self.clone_into_box()

0 commit comments

Comments
 (0)