From 0c8007dc940fb7dd142edda5689bb5fb3de974e4 Mon Sep 17 00:00:00 2001 From: Marko Mikulicic Date: Thu, 1 Oct 2020 12:08:41 +0200 Subject: [PATCH] Simplify matchers --- src/matchers.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/matchers.rs b/src/matchers.rs index 78f5b08..835e321 100644 --- a/src/matchers.rs +++ b/src/matchers.rs @@ -25,8 +25,8 @@ pub struct WildcardedChild {} impl Matcher for WildcardedChild { fn select<'a>(&self, node: &'a Value) -> Box + '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()) } @@ -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 + '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()) } }