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

Commit b0fc08f

Browse files
author
Marko Mikulicic
committed
Use a type alias to remove type decl noise
1 parent 53d4049 commit b0fc08f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/matchers.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,27 @@
77
use serde_json::Value;
88
use std::iter;
99

10+
/// An iterator over matcher selection results.
11+
type Iter<'a> = Box<dyn Iterator<Item = &'a Value> + 'a>;
12+
1013
// Matcher maps a node to a list of nodes. If the input node is not matched by the matcher or
1114
// the matcher does not select any subnodes of the input node, then the result is empty.
1215
pub trait Matcher {
13-
fn select<'a>(&'a self, node: &'a Value) -> Box<dyn Iterator<Item = &'a Value> + 'a>;
16+
fn select<'a>(&'a self, node: &'a Value) -> Iter<'a>;
1417
}
1518

1619
pub struct RootSelector {}
1720

1821
impl Matcher for RootSelector {
19-
fn select<'a>(&'a self, node: &'a Value) -> Box<dyn Iterator<Item = &'a Value> + 'a> {
22+
fn select<'a>(&'a self, node: &'a Value) -> Iter<'a> {
2023
Box::new(iter::once(node))
2124
}
2225
}
2326

2427
pub struct WildcardedChild {}
2528

2629
impl Matcher for WildcardedChild {
27-
fn select<'a>(&self, node: &'a Value) -> Box<dyn Iterator<Item = &'a Value> + 'a> {
30+
fn select<'a>(&self, node: &'a Value) -> Iter<'a> {
2831
if let Some(m) = node.as_object() {
2932
Box::new(m.values())
3033
} else {
@@ -42,7 +45,7 @@ pub fn new_child_matcher(name: String) -> Child {
4245
}
4346

4447
impl Matcher for Child {
45-
fn select<'a>(&'a self, node: &'a Value) -> Box<dyn Iterator<Item = &'a Value> + 'a> {
48+
fn select<'a>(&'a self, node: &'a Value) -> Iter<'a> {
4649
Box::new(node.get(&self.name).into_iter())
4750
}
4851
}
@@ -56,7 +59,7 @@ pub fn new_union(elements: Vec<Box<dyn Matcher>>) -> Union {
5659
}
5760

5861
impl Matcher for Union {
59-
fn select<'a>(&'a self, node: &'a Value) -> Box<dyn Iterator<Item = &'a Value> + 'a> {
62+
fn select<'a>(&'a self, node: &'a Value) -> Iter<'a> {
6063
Box::new(self.elements.iter().flat_map(move |it| it.select(node)))
6164
}
6265
}

0 commit comments

Comments
 (0)