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

Commit 8bdfd5a

Browse files
authored
Merge pull request #9 from mkmik/alias
Use a type alias to remove type decl noise
2 parents 63ae238 + c9f5409 commit 8bdfd5a

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 {
@@ -44,7 +47,7 @@ impl Child {
4447
}
4548

4649
impl Matcher for Child {
47-
fn select<'a>(&'a self, node: &'a Value) -> Box<dyn Iterator<Item = &'a Value> + 'a> {
50+
fn select<'a>(&'a self, node: &'a Value) -> Iter<'a> {
4851
Box::new(node.get(&self.name).into_iter())
4952
}
5053
}
@@ -60,7 +63,7 @@ impl Union {
6063
}
6164

6265
impl Matcher for Union {
63-
fn select<'a>(&'a self, node: &'a Value) -> Box<dyn Iterator<Item = &'a Value> + 'a> {
66+
fn select<'a>(&'a self, node: &'a Value) -> Iter<'a> {
6467
Box::new(self.elements.iter().flat_map(move |it| it.select(node)))
6568
}
6669
}

0 commit comments

Comments
 (0)