1
1
use std:: { ops:: Deref , time:: Duration } ;
2
2
3
- use async_trait:: async_trait;
4
- use futures:: stream:: StreamExt ;
3
+ use futures:: { future:: BoxFuture , stream:: StreamExt , FutureExt } ;
5
4
use serde:: {
6
5
de:: { self , Deserializer } ,
7
6
Deserialize ,
@@ -16,12 +15,11 @@ use crate::{
16
15
Collection ,
17
16
} ;
18
17
19
- #[ async_trait]
20
18
pub ( super ) trait TestOperation {
21
19
/// The command names to monitor as part of this test.
22
20
fn command_names ( & self ) -> & [ & str ] ;
23
21
24
- async fn execute ( & self , collection : Collection < Document > ) -> Result < ( ) > ;
22
+ fn execute ( & self , collection : Collection < Document > ) -> BoxFuture < Result < ( ) > > ;
25
23
}
26
24
27
25
pub ( super ) struct AnyTestOperation {
@@ -75,17 +73,19 @@ pub(super) struct DeleteMany {
75
73
filter : Document ,
76
74
}
77
75
78
- #[ async_trait]
79
76
impl TestOperation for DeleteMany {
80
77
fn command_names ( & self ) -> & [ & str ] {
81
78
& [ "delete" ]
82
79
}
83
80
84
- async fn execute ( & self , collection : Collection < Document > ) -> Result < ( ) > {
85
- collection
86
- . delete_many ( self . filter . clone ( ) , None )
87
- . await
88
- . map ( |_| ( ) )
81
+ fn execute ( & self , collection : Collection < Document > ) -> BoxFuture < Result < ( ) > > {
82
+ async move {
83
+ collection
84
+ . delete_many ( self . filter . clone ( ) , None )
85
+ . await
86
+ . map ( |_| ( ) )
87
+ }
88
+ . boxed ( )
89
89
}
90
90
}
91
91
@@ -94,17 +94,19 @@ pub(super) struct DeleteOne {
94
94
filter : Document ,
95
95
}
96
96
97
- #[ async_trait]
98
97
impl TestOperation for DeleteOne {
99
98
fn command_names ( & self ) -> & [ & str ] {
100
99
& [ "delete" ]
101
100
}
102
101
103
- async fn execute ( & self , collection : Collection < Document > ) -> Result < ( ) > {
104
- collection
105
- . delete_one ( self . filter . clone ( ) , None )
106
- . await
107
- . map ( |_| ( ) )
102
+ fn execute ( & self , collection : Collection < Document > ) -> BoxFuture < Result < ( ) > > {
103
+ async move {
104
+ collection
105
+ . delete_one ( self . filter . clone ( ) , None )
106
+ . await
107
+ . map ( |_| ( ) )
108
+ }
109
+ . boxed ( )
108
110
}
109
111
}
110
112
@@ -159,31 +161,33 @@ pub(super) struct Find {
159
161
modifiers : Option < FindModifiers > ,
160
162
}
161
163
162
- #[ async_trait]
163
164
impl TestOperation for Find {
164
165
fn command_names ( & self ) -> & [ & str ] {
165
166
& [ "find" , "getMore" ]
166
167
}
167
168
168
- async fn execute ( & self , collection : Collection < Document > ) -> Result < ( ) > {
169
- let mut options = FindOptions {
170
- sort : self . sort . clone ( ) ,
171
- skip : self . skip ,
172
- batch_size : self . batch_size . map ( |i| i as u32 ) ,
173
- limit : self . limit ,
174
- ..Default :: default ( )
175
- } ;
176
-
177
- if let Some ( ref modifiers) = self . modifiers {
178
- modifiers. update_options ( & mut options) ;
179
- }
180
-
181
- let mut cursor = collection. find ( self . filter . clone ( ) , options) . await ?;
182
-
183
- while let Some ( result) = cursor. next ( ) . await {
184
- result?;
169
+ fn execute ( & self , collection : Collection < Document > ) -> BoxFuture < Result < ( ) > > {
170
+ async move {
171
+ let mut options = FindOptions {
172
+ sort : self . sort . clone ( ) ,
173
+ skip : self . skip ,
174
+ batch_size : self . batch_size . map ( |i| i as u32 ) ,
175
+ limit : self . limit ,
176
+ ..Default :: default ( )
177
+ } ;
178
+
179
+ if let Some ( ref modifiers) = self . modifiers {
180
+ modifiers. update_options ( & mut options) ;
181
+ }
182
+
183
+ let mut cursor = collection. find ( self . filter . clone ( ) , options) . await ?;
184
+
185
+ while let Some ( result) = cursor. next ( ) . await {
186
+ result?;
187
+ }
188
+ Ok ( ( ) )
185
189
}
186
- Ok ( ( ) )
190
+ . boxed ( )
187
191
}
188
192
}
189
193
@@ -194,17 +198,19 @@ pub(super) struct InsertMany {
194
198
options : Option < InsertManyOptions > ,
195
199
}
196
200
197
- #[ async_trait]
198
201
impl TestOperation for InsertMany {
199
202
fn command_names ( & self ) -> & [ & str ] {
200
203
& [ "insert" ]
201
204
}
202
205
203
- async fn execute ( & self , collection : Collection < Document > ) -> Result < ( ) > {
204
- collection
205
- . insert_many ( self . documents . clone ( ) , self . options . clone ( ) )
206
- . await
207
- . map ( |_| ( ) )
206
+ fn execute ( & self , collection : Collection < Document > ) -> BoxFuture < Result < ( ) > > {
207
+ async move {
208
+ collection
209
+ . insert_many ( self . documents . clone ( ) , self . options . clone ( ) )
210
+ . await
211
+ . map ( |_| ( ) )
212
+ }
213
+ . boxed ( )
208
214
}
209
215
}
210
216
@@ -213,17 +219,19 @@ pub(super) struct InsertOne {
213
219
document : Document ,
214
220
}
215
221
216
- #[ async_trait]
217
222
impl TestOperation for InsertOne {
218
223
fn command_names ( & self ) -> & [ & str ] {
219
224
& [ "insert" ]
220
225
}
221
226
222
- async fn execute ( & self , collection : Collection < Document > ) -> Result < ( ) > {
223
- collection
224
- . insert_one ( self . document . clone ( ) , None )
225
- . await
226
- . map ( |_| ( ) )
227
+ fn execute ( & self , collection : Collection < Document > ) -> BoxFuture < Result < ( ) > > {
228
+ async move {
229
+ collection
230
+ . insert_one ( self . document . clone ( ) , None )
231
+ . await
232
+ . map ( |_| ( ) )
233
+ }
234
+ . boxed ( )
227
235
}
228
236
}
229
237
@@ -233,17 +241,19 @@ pub(super) struct UpdateMany {
233
241
update : Document ,
234
242
}
235
243
236
- #[ async_trait]
237
244
impl TestOperation for UpdateMany {
238
245
fn command_names ( & self ) -> & [ & str ] {
239
246
& [ "update" ]
240
247
}
241
248
242
- async fn execute ( & self , collection : Collection < Document > ) -> Result < ( ) > {
243
- collection
244
- . update_many ( self . filter . clone ( ) , self . update . clone ( ) , None )
245
- . await
246
- . map ( |_| ( ) )
249
+ fn execute ( & self , collection : Collection < Document > ) -> BoxFuture < Result < ( ) > > {
250
+ async move {
251
+ collection
252
+ . update_many ( self . filter . clone ( ) , self . update . clone ( ) , None )
253
+ . await
254
+ . map ( |_| ( ) )
255
+ }
256
+ . boxed ( )
247
257
}
248
258
}
249
259
@@ -255,21 +265,23 @@ pub(super) struct UpdateOne {
255
265
upsert : Option < bool > ,
256
266
}
257
267
258
- #[ async_trait]
259
268
impl TestOperation for UpdateOne {
260
269
fn command_names ( & self ) -> & [ & str ] {
261
270
& [ "update" ]
262
271
}
263
272
264
- async fn execute ( & self , collection : Collection < Document > ) -> Result < ( ) > {
265
- let options = self . upsert . map ( |b| UpdateOptions {
266
- upsert : Some ( b) ,
267
- ..Default :: default ( )
268
- } ) ;
269
- collection
270
- . update_one ( self . filter . clone ( ) , self . update . clone ( ) , options)
271
- . await
272
- . map ( |_| ( ) )
273
+ fn execute ( & self , collection : Collection < Document > ) -> BoxFuture < Result < ( ) > > {
274
+ async move {
275
+ let options = self . upsert . map ( |b| UpdateOptions {
276
+ upsert : Some ( b) ,
277
+ ..Default :: default ( )
278
+ } ) ;
279
+ collection
280
+ . update_one ( self . filter . clone ( ) , self . update . clone ( ) , options)
281
+ . await
282
+ . map ( |_| ( ) )
283
+ }
284
+ . boxed ( )
273
285
}
274
286
}
275
287
0 commit comments