File tree Expand file tree Collapse file tree 2 files changed +5
-12
lines changed Expand file tree Collapse file tree 2 files changed +5
-12
lines changed Original file line number Diff line number Diff line change 5
5
*/
6
6
7
7
use serde_json:: Value ;
8
+ use std:: iter:: once;
8
9
9
10
// Matcher maps a node to a list of nodes. If the input node is not matched by the matcher or
10
11
// the matcher does not select any subnodes of the input node, then the result is empty.
11
12
pub trait Matcher {
12
- fn select < ' a > ( & self , node : & ' a Value ) -> Vec < & ' a Value > ;
13
+ fn select < ' a > ( & self , node : & ' a Value ) -> Box < dyn Iterator < Item = & ' a Value > + ' a > ;
13
14
}
14
15
15
16
pub struct RootSelector { }
16
17
17
18
impl Matcher for RootSelector {
18
- fn select < ' a > ( & self , node : & ' a Value ) -> Vec < & ' a Value > {
19
- let mut results = Vec :: new ( ) ;
20
- results. push ( node) ;
21
- results
19
+ fn select < ' a > ( & self , node : & ' a Value ) -> Box < dyn Iterator < Item = & ' a Value > + ' a > {
20
+ Box :: new ( once ( node) )
22
21
}
23
22
}
Original file line number Diff line number Diff line change @@ -28,14 +28,8 @@ impl Path for SelectorPath<'_> {
28
28
// pass nodes, starting with document alone, through each matcher in turn
29
29
Ok ( ( & self . matchers )
30
30
. iter ( )
31
- . fold ( doc_node ( document) , |nodes, matcher| {
31
+ . fold ( vec ! [ document] , |nodes, matcher| {
32
32
nodes. iter ( ) . flat_map ( |node| matcher. select ( node) ) . collect ( )
33
33
} ) )
34
34
}
35
35
}
36
-
37
- fn doc_node < ' a > ( document : & ' a Value ) -> Vec < & ' a Value > {
38
- let mut nodes = Vec :: new ( ) ;
39
- nodes. push ( document) ;
40
- nodes
41
- }
You can’t perform that action at this time.
0 commit comments