1
1
use crate :: body:: Body ;
2
2
use crate :: extract:: { DefaultBodyLimitKind , FromRequest , FromRequestParts , Request } ;
3
- use futures_util :: future:: BoxFuture ;
3
+ use std :: future:: Future ;
4
4
5
5
mod sealed {
6
6
pub trait Sealed { }
@@ -20,7 +20,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
20
20
///
21
21
/// ```
22
22
/// use axum::{
23
- /// async_trait,
24
23
/// extract::{Request, FromRequest},
25
24
/// body::Body,
26
25
/// http::{header::CONTENT_TYPE, StatusCode},
@@ -30,7 +29,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
30
29
///
31
30
/// struct FormOrJson<T>(T);
32
31
///
33
- /// #[async_trait]
34
32
/// impl<S, T> FromRequest<S> for FormOrJson<T>
35
33
/// where
36
34
/// Json<T>: FromRequest<()>,
@@ -67,7 +65,7 @@ pub trait RequestExt: sealed::Sealed + Sized {
67
65
/// }
68
66
/// }
69
67
/// ```
70
- fn extract < E , M > ( self ) -> BoxFuture < ' static , Result < E , E :: Rejection > >
68
+ fn extract < E , M > ( self ) -> impl Future < Output = Result < E , E :: Rejection > > + Send
71
69
where
72
70
E : FromRequest < ( ) , M > + ' static ,
73
71
M : ' static ;
@@ -83,7 +81,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
83
81
///
84
82
/// ```
85
83
/// use axum::{
86
- /// async_trait,
87
84
/// body::Body,
88
85
/// extract::{Request, FromRef, FromRequest},
89
86
/// RequestExt,
@@ -93,7 +90,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
93
90
/// requires_state: RequiresState,
94
91
/// }
95
92
///
96
- /// #[async_trait]
97
93
/// impl<S> FromRequest<S> for MyExtractor
98
94
/// where
99
95
/// String: FromRef<S>,
@@ -111,7 +107,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
111
107
/// // some extractor that consumes the request body and requires state
112
108
/// struct RequiresState { /* ... */ }
113
109
///
114
- /// #[async_trait]
115
110
/// impl<S> FromRequest<S> for RequiresState
116
111
/// where
117
112
/// String: FromRef<S>,
@@ -124,7 +119,10 @@ pub trait RequestExt: sealed::Sealed + Sized {
124
119
/// # }
125
120
/// }
126
121
/// ```
127
- fn extract_with_state < E , S , M > ( self , state : & S ) -> BoxFuture < ' _ , Result < E , E :: Rejection > >
122
+ fn extract_with_state < E , S , M > (
123
+ self ,
124
+ state : & S ,
125
+ ) -> impl Future < Output = Result < E , E :: Rejection > > + Send
128
126
where
129
127
E : FromRequest < S , M > + ' static ,
130
128
S : Send + Sync ;
@@ -137,7 +135,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
137
135
///
138
136
/// ```
139
137
/// use axum::{
140
- /// async_trait,
141
138
/// extract::{Path, Request, FromRequest},
142
139
/// response::{IntoResponse, Response},
143
140
/// body::Body,
@@ -154,7 +151,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
154
151
/// payload: T,
155
152
/// }
156
153
///
157
- /// #[async_trait]
158
154
/// impl<S, T> FromRequest<S> for MyExtractor<T>
159
155
/// where
160
156
/// S: Send + Sync,
@@ -179,7 +175,7 @@ pub trait RequestExt: sealed::Sealed + Sized {
179
175
/// }
180
176
/// }
181
177
/// ```
182
- fn extract_parts < E > ( & mut self ) -> BoxFuture < ' _ , Result < E , E :: Rejection > >
178
+ fn extract_parts < E > ( & mut self ) -> impl Future < Output = Result < E , E :: Rejection > > + Send
183
179
where
184
180
E : FromRequestParts < ( ) > + ' static ;
185
181
@@ -191,7 +187,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
191
187
///
192
188
/// ```
193
189
/// use axum::{
194
- /// async_trait,
195
190
/// extract::{Request, FromRef, FromRequest, FromRequestParts},
196
191
/// http::request::Parts,
197
192
/// response::{IntoResponse, Response},
@@ -204,7 +199,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
204
199
/// payload: T,
205
200
/// }
206
201
///
207
- /// #[async_trait]
208
202
/// impl<S, T> FromRequest<S> for MyExtractor<T>
209
203
/// where
210
204
/// String: FromRef<S>,
@@ -234,7 +228,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
234
228
///
235
229
/// struct RequiresState {}
236
230
///
237
- /// #[async_trait]
238
231
/// impl<S> FromRequestParts<S> for RequiresState
239
232
/// where
240
233
/// String: FromRef<S>,
@@ -250,7 +243,7 @@ pub trait RequestExt: sealed::Sealed + Sized {
250
243
fn extract_parts_with_state < ' a , E , S > (
251
244
& ' a mut self ,
252
245
state : & ' a S ,
253
- ) -> BoxFuture < ' a , Result < E , E :: Rejection > >
246
+ ) -> impl Future < Output = Result < E , E :: Rejection > > + Send + ' a
254
247
where
255
248
E : FromRequestParts < S > + ' static ,
256
249
S : Send + Sync ;
@@ -267,33 +260,36 @@ pub trait RequestExt: sealed::Sealed + Sized {
267
260
}
268
261
269
262
impl RequestExt for Request {
270
- fn extract < E , M > ( self ) -> BoxFuture < ' static , Result < E , E :: Rejection > >
263
+ fn extract < E , M > ( self ) -> impl Future < Output = Result < E , E :: Rejection > > + Send
271
264
where
272
265
E : FromRequest < ( ) , M > + ' static ,
273
266
M : ' static ,
274
267
{
275
268
self . extract_with_state ( & ( ) )
276
269
}
277
270
278
- fn extract_with_state < E , S , M > ( self , state : & S ) -> BoxFuture < ' _ , Result < E , E :: Rejection > >
271
+ fn extract_with_state < E , S , M > (
272
+ self ,
273
+ state : & S ,
274
+ ) -> impl Future < Output = Result < E , E :: Rejection > > + Send
279
275
where
280
276
E : FromRequest < S , M > + ' static ,
281
277
S : Send + Sync ,
282
278
{
283
279
E :: from_request ( self , state)
284
280
}
285
281
286
- fn extract_parts < E > ( & mut self ) -> BoxFuture < ' _ , Result < E , E :: Rejection > >
282
+ fn extract_parts < E > ( & mut self ) -> impl Future < Output = Result < E , E :: Rejection > > + Send
287
283
where
288
284
E : FromRequestParts < ( ) > + ' static ,
289
285
{
290
286
self . extract_parts_with_state ( & ( ) )
291
287
}
292
288
293
- fn extract_parts_with_state < ' a , E , S > (
289
+ async fn extract_parts_with_state < ' a , E , S > (
294
290
& ' a mut self ,
295
291
state : & ' a S ,
296
- ) -> BoxFuture < ' a , Result < E , E :: Rejection > >
292
+ ) -> Result < E , E :: Rejection >
297
293
where
298
294
E : FromRequestParts < S > + ' static ,
299
295
S : Send + Sync ,
@@ -306,17 +302,15 @@ impl RequestExt for Request {
306
302
* req. extensions_mut ( ) = std:: mem:: take ( self . extensions_mut ( ) ) ;
307
303
let ( mut parts, ( ) ) = req. into_parts ( ) ;
308
304
309
- Box :: pin ( async move {
310
- let result = E :: from_request_parts ( & mut parts, state) . await ;
305
+ let result = E :: from_request_parts ( & mut parts, state) . await ;
311
306
312
- * self . version_mut ( ) = parts. version ;
313
- * self . method_mut ( ) = parts. method . clone ( ) ;
314
- * self . uri_mut ( ) = parts. uri . clone ( ) ;
315
- * self . headers_mut ( ) = std:: mem:: take ( & mut parts. headers ) ;
316
- * self . extensions_mut ( ) = std:: mem:: take ( & mut parts. extensions ) ;
307
+ * self . version_mut ( ) = parts. version ;
308
+ * self . method_mut ( ) = parts. method . clone ( ) ;
309
+ * self . uri_mut ( ) = parts. uri . clone ( ) ;
310
+ * self . headers_mut ( ) = std:: mem:: take ( & mut parts. headers ) ;
311
+ * self . extensions_mut ( ) = std:: mem:: take ( & mut parts. extensions ) ;
317
312
318
- result
319
- } )
313
+ result
320
314
}
321
315
322
316
fn with_limited_body ( self ) -> Request {
@@ -345,7 +339,6 @@ mod tests {
345
339
ext_traits:: tests:: { RequiresState , State } ,
346
340
extract:: FromRef ,
347
341
} ;
348
- use async_trait:: async_trait;
349
342
use http:: Method ;
350
343
351
344
#[ tokio:: test]
@@ -414,7 +407,6 @@ mod tests {
414
407
body : String ,
415
408
}
416
409
417
- #[ async_trait]
418
410
impl < S > FromRequest < S > for WorksForCustomExtractor
419
411
where
420
412
S : Send + Sync ,
0 commit comments