1
1
use crate :: framework:: implementation:: Implementation ;
2
- use ouroboros :: self_referencing ;
2
+ use rsonpath :: { engine :: Compiler , input :: MmapInput } ;
3
3
use rsonpath:: {
4
- engine:: main:: MainEngine ,
4
+ engine:: { main:: MainEngine , Engine } ,
5
5
input:: OwnedBytes ,
6
6
result:: { Match , Sink } ,
7
7
} ;
8
- use rsonpath:: {
9
- engine:: { Compiler , Engine } ,
10
- input:: MmapInput ,
11
- } ;
12
- use rsonpath_syntax:: JsonPathQuery ;
13
8
use std:: { convert:: Infallible , fmt:: Display , fs, io} ;
14
9
use thiserror:: Error ;
15
10
@@ -18,16 +13,8 @@ pub struct RsonpathCount {}
18
13
pub struct RsonpathMmap { }
19
14
pub struct RsonpathMmapCount { }
20
15
21
- #[ self_referencing( ) ]
22
- pub struct RsonpathQuery {
23
- query : JsonPathQuery ,
24
- #[ borrows( query) ]
25
- #[ not_covariant]
26
- engine : MainEngine < ' this > ,
27
- }
28
-
29
16
impl Implementation for Rsonpath {
30
- type Query = RsonpathQuery ;
17
+ type Query = MainEngine ;
31
18
32
19
type File = OwnedBytes < Vec < u8 > > ;
33
20
@@ -52,25 +39,20 @@ impl Implementation for Rsonpath {
52
39
53
40
fn compile_query ( & self , query : & str ) -> Result < Self :: Query , Self :: Error > {
54
41
let query = rsonpath_syntax:: parse ( query) . unwrap ( ) ;
42
+ let engine = MainEngine :: compile_query ( & query) . map_err ( RsonpathError :: CompilerError ) ?;
55
43
56
- let rsonpath = RsonpathQuery :: try_new ( query, |query| {
57
- MainEngine :: compile_query ( query) . map_err ( RsonpathError :: CompilerError )
58
- } ) ?;
59
-
60
- Ok ( rsonpath)
44
+ Ok ( engine)
61
45
}
62
46
63
47
fn run ( & self , query : & Self :: Query , file : & Self :: File ) -> Result < Self :: Result < ' _ > , Self :: Error > {
64
- query
65
- . with_engine ( |engine| engine. matches ( file, & mut VoidSink ) )
66
- . map_err ( RsonpathError :: EngineError ) ?;
48
+ query. matches ( file, & mut VoidSink ) . map_err ( RsonpathError :: EngineError ) ?;
67
49
68
50
Ok ( "[not collected]" )
69
51
}
70
52
}
71
53
72
54
impl Implementation for RsonpathCount {
73
- type Query = RsonpathQuery ;
55
+ type Query = MainEngine ;
74
56
75
57
type File = OwnedBytes < Vec < u8 > > ;
76
58
@@ -95,25 +77,20 @@ impl Implementation for RsonpathCount {
95
77
96
78
fn compile_query ( & self , query : & str ) -> Result < Self :: Query , Self :: Error > {
97
79
let query = rsonpath_syntax:: parse ( query) . unwrap ( ) ;
80
+ let engine = MainEngine :: compile_query ( & query) . map_err ( RsonpathError :: CompilerError ) ?;
98
81
99
- let rsonpath = RsonpathQuery :: try_new ( query, |query| {
100
- MainEngine :: compile_query ( query) . map_err ( RsonpathError :: CompilerError )
101
- } ) ?;
102
-
103
- Ok ( rsonpath)
82
+ Ok ( engine)
104
83
}
105
84
106
85
fn run ( & self , query : & Self :: Query , file : & Self :: File ) -> Result < Self :: Result < ' _ > , Self :: Error > {
107
- query
108
- . with_engine ( |engine| engine. count ( file) )
109
- . map_err ( RsonpathError :: EngineError ) ?;
86
+ query. count ( file) . map_err ( RsonpathError :: EngineError ) ?;
110
87
111
88
Ok ( "[not collected]" )
112
89
}
113
90
}
114
91
115
92
impl Implementation for RsonpathMmap {
116
- type Query = RsonpathQuery ;
93
+ type Query = MainEngine ;
117
94
118
95
type File = MmapInput ;
119
96
@@ -138,25 +115,20 @@ impl Implementation for RsonpathMmap {
138
115
139
116
fn compile_query ( & self , query : & str ) -> Result < Self :: Query , Self :: Error > {
140
117
let query = rsonpath_syntax:: parse ( query) . unwrap ( ) ;
118
+ let engine = MainEngine :: compile_query ( & query) . map_err ( RsonpathError :: CompilerError ) ?;
141
119
142
- let rsonpath = RsonpathQuery :: try_new ( query, |query| {
143
- MainEngine :: compile_query ( query) . map_err ( RsonpathError :: CompilerError )
144
- } ) ?;
145
-
146
- Ok ( rsonpath)
120
+ Ok ( engine)
147
121
}
148
122
149
123
fn run ( & self , query : & Self :: Query , file : & Self :: File ) -> Result < Self :: Result < ' _ > , Self :: Error > {
150
- query
151
- . with_engine ( |engine| engine. matches ( file, & mut VoidSink ) )
152
- . map_err ( RsonpathError :: EngineError ) ?;
124
+ query. matches ( file, & mut VoidSink ) . map_err ( RsonpathError :: EngineError ) ?;
153
125
154
126
Ok ( "[not collected]" )
155
127
}
156
128
}
157
129
158
130
impl Implementation for RsonpathMmapCount {
159
- type Query = RsonpathQuery ;
131
+ type Query = MainEngine ;
160
132
161
133
type File = MmapInput ;
162
134
@@ -181,18 +153,13 @@ impl Implementation for RsonpathMmapCount {
181
153
182
154
fn compile_query ( & self , query : & str ) -> Result < Self :: Query , Self :: Error > {
183
155
let query = rsonpath_syntax:: parse ( query) . unwrap ( ) ;
156
+ let engine = MainEngine :: compile_query ( & query) . map_err ( RsonpathError :: CompilerError ) ?;
184
157
185
- let rsonpath = RsonpathQuery :: try_new ( query, |query| {
186
- MainEngine :: compile_query ( query) . map_err ( RsonpathError :: CompilerError )
187
- } ) ?;
188
-
189
- Ok ( rsonpath)
158
+ Ok ( engine)
190
159
}
191
160
192
161
fn run ( & self , query : & Self :: Query , file : & Self :: File ) -> Result < Self :: Result < ' _ > , Self :: Error > {
193
- query
194
- . with_engine ( |engine| engine. count ( file) )
195
- . map_err ( RsonpathError :: EngineError ) ?;
162
+ query. count ( file) . map_err ( RsonpathError :: EngineError ) ?;
196
163
197
164
Ok ( "[not collected]" )
198
165
}
0 commit comments