File tree Expand file tree Collapse file tree 1 file changed +12
-15
lines changed Expand file tree Collapse file tree 1 file changed +12
-15
lines changed Original file line number Diff line number Diff line change @@ -39,20 +39,17 @@ pub fn parse(selector: &str) -> Result<Box<dyn Path>, String> {
39
39
40
40
impl Path for SelectorPath < ' _ > {
41
41
fn find < ' a > ( & self , document : & ' a Value ) -> Result < Vec < & ' a Value > , FindError > {
42
- let mut nodes = Vec :: new ( ) ;
43
- nodes. push ( document) ;
44
-
45
- // pass nodes through each matcher in turn
46
- for m in & self . matchers {
47
- let mut selected = Vec :: new ( ) ;
48
- for n in & nodes {
49
- for r in m. select ( n) {
50
- selected. push ( r) ;
51
- }
52
- }
53
- nodes = selected;
54
- }
55
-
56
- Ok ( nodes)
42
+ // pass nodes, starting with document alone, through each matcher in turn
43
+ Ok ( ( & self . matchers )
44
+ . iter ( )
45
+ . fold ( doc_node ( document) , |nodes, matcher| {
46
+ nodes. iter ( ) . flat_map ( |node| matcher. select ( node) ) . collect ( )
47
+ } ) )
57
48
}
58
49
}
50
+
51
+ fn doc_node < ' a > ( document : & ' a Value ) -> Vec < & ' a Value > {
52
+ let mut nodes = Vec :: new ( ) ;
53
+ nodes. push ( document) ;
54
+ nodes
55
+ }
You can’t perform that action at this time.
0 commit comments