Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit 53d4049

Browse files
authored
Merge pull request #8 from mkmik/cleanup
Simplify matchers
2 parents b8315bd + 0c8007d commit 53d4049

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

src/matchers.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ pub struct WildcardedChild {}
2525

2626
impl Matcher for WildcardedChild {
2727
fn select<'a>(&self, node: &'a Value) -> Box<dyn Iterator<Item = &'a Value> + 'a> {
28-
if node.is_object() {
29-
Box::new(node.as_object().unwrap().into_iter().map(|(_k, v)| v))
28+
if let Some(m) = node.as_object() {
29+
Box::new(m.values())
3030
} else {
3131
Box::new(iter::empty())
3232
}
@@ -43,16 +43,7 @@ pub fn new_child_matcher(name: String) -> Child {
4343

4444
impl Matcher for Child {
4545
fn select<'a>(&'a self, node: &'a Value) -> Box<dyn Iterator<Item = &'a Value> + 'a> {
46-
if node.is_object() {
47-
let mapping = node.as_object().unwrap();
48-
if mapping.contains_key(&self.name) {
49-
Box::new(iter::once(&mapping[&self.name]))
50-
} else {
51-
Box::new(iter::empty())
52-
}
53-
} else {
54-
Box::new(iter::empty())
55-
}
46+
Box::new(node.get(&self.name).into_iter())
5647
}
5748
}
5849

0 commit comments

Comments
 (0)