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

Simplify matchers #8

Merged
merged 1 commit into from
Oct 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions src/matchers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub struct WildcardedChild {}

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

impl Matcher for Child {
fn select<'a>(&'a self, node: &'a Value) -> Box<dyn Iterator<Item = &'a Value> + 'a> {
if node.is_object() {
let mapping = node.as_object().unwrap();
if mapping.contains_key(&self.name) {
Box::new(iter::once(&mapping[&self.name]))
} else {
Box::new(iter::empty())
}
} else {
Box::new(iter::empty())
}
Box::new(node.get(&self.name).into_iter())
}
}

Expand Down