@@ -11,24 +11,24 @@ use std::{collections::HashMap, fmt::Display};
11
11
///
12
12
/// This trait is automatically implemented for `Fn` types, and so is rarely implemented
13
13
/// directly by Spin users.
14
- #[ async_trait]
15
- pub trait Handler : Send + Sync {
14
+ #[ async_trait( ? Send ) ]
15
+ pub trait Handler {
16
16
/// Invoke the handler.
17
17
async fn handle ( & self , req : Request , params : Params ) -> Response ;
18
18
}
19
19
20
- #[ async_trait]
20
+ #[ async_trait( ? Send ) ]
21
21
impl Handler for Box < dyn Handler > {
22
22
async fn handle ( & self , req : Request , params : Params ) -> Response {
23
23
self . as_ref ( ) . handle ( req, params) . await
24
24
}
25
25
}
26
26
27
- #[ async_trait]
27
+ #[ async_trait( ? Send ) ]
28
28
impl < F , Fut > Handler for F
29
29
where
30
- F : Fn ( Request , Params ) -> Fut + Send + Sync + ' static ,
31
- Fut : Future < Output = Response > + Send + ' static ,
30
+ F : Fn ( Request , Params ) -> Fut + ' static ,
31
+ Fut : Future < Output = Response > + ' static ,
32
32
{
33
33
async fn handle ( & self , req : Request , params : Params ) -> Response {
34
34
let fut = ( self ) ( req, params) ;
@@ -154,10 +154,10 @@ impl Router {
154
154
/// Register a handler at the path for all methods.
155
155
pub fn any < F , Req , Resp > ( & mut self , path : & str , handler : F )
156
156
where
157
- F : Fn ( Req , Params ) -> Resp + ' static + Send + Sync ,
158
- Req : TryFromRequest + ' static + Send ,
159
- Req :: Error : IntoResponse + Send + ' static ,
160
- Resp : IntoResponse + ' static + Send ,
157
+ F : Fn ( Req , Params ) -> Resp + ' static ,
158
+ Req : TryFromRequest + ' static ,
159
+ Req :: Error : IntoResponse + ' static ,
160
+ Resp : IntoResponse + ' static ,
161
161
{
162
162
let handler = move |req, params| {
163
163
let res = TryFromRequest :: try_from_request ( req) . map ( |r| handler ( r, params) ) ;
@@ -175,11 +175,11 @@ impl Router {
175
175
/// Register an async handler at the path for all methods.
176
176
pub fn any_async < F , Fut , I , O > ( & mut self , path : & str , handler : F )
177
177
where
178
- F : Fn ( I , Params ) -> Fut + ' static + Send + Sync ,
179
- Fut : Future < Output = O > + Send + ' static ,
180
- I : TryFromRequest + ' static + Send ,
181
- I :: Error : IntoResponse + Send + ' static ,
182
- O : IntoResponse + ' static + Send ,
178
+ F : Fn ( I , Params ) -> Fut + ' static ,
179
+ Fut : Future < Output = O > + ' static ,
180
+ I : TryFromRequest + ' static ,
181
+ I :: Error : IntoResponse + ' static ,
182
+ O : IntoResponse + ' static ,
183
183
{
184
184
let handler = move |req, params| {
185
185
let res = TryFromRequest :: try_from_request ( req) . map ( |r| handler ( r, params) ) ;
@@ -197,10 +197,10 @@ impl Router {
197
197
/// Register a handler at the path for the specified HTTP method.
198
198
pub fn add < F , Req , Resp > ( & mut self , path : & str , method : Method , handler : F )
199
199
where
200
- F : Fn ( Req , Params ) -> Resp + ' static + Send + Sync ,
201
- Req : TryFromRequest + ' static + Send ,
202
- Req :: Error : IntoResponse + Send + ' static ,
203
- Resp : IntoResponse + ' static + Send ,
200
+ F : Fn ( Req , Params ) -> Resp + ' static ,
201
+ Req : TryFromRequest + ' static ,
202
+ Req :: Error : IntoResponse + ' static ,
203
+ Resp : IntoResponse + ' static ,
204
204
{
205
205
let handler = move |req, params| {
206
206
let res = TryFromRequest :: try_from_request ( req) . map ( |r| handler ( r, params) ) ;
@@ -218,11 +218,11 @@ impl Router {
218
218
/// Register an async handler at the path for the specified HTTP method.
219
219
pub fn add_async < F , Fut , I , O > ( & mut self , path : & str , method : Method , handler : F )
220
220
where
221
- F : Fn ( I , Params ) -> Fut + ' static + Send + Sync ,
222
- Fut : Future < Output = O > + Send + ' static ,
223
- I : TryFromRequest + ' static + Send ,
224
- I :: Error : IntoResponse + Send + ' static ,
225
- O : IntoResponse + ' static + Send ,
221
+ F : Fn ( I , Params ) -> Fut + ' static ,
222
+ Fut : Future < Output = O > + ' static ,
223
+ I : TryFromRequest + ' static ,
224
+ I :: Error : IntoResponse + ' static ,
225
+ O : IntoResponse + ' static ,
226
226
{
227
227
let handler = move |req, params| {
228
228
let res = TryFromRequest :: try_from_request ( req) . map ( |r| handler ( r, params) ) ;
@@ -244,160 +244,160 @@ impl Router {
244
244
/// Register a handler at the path for the HTTP GET method.
245
245
pub fn get < F , Req , Resp > ( & mut self , path : & str , handler : F )
246
246
where
247
- F : Fn ( Req , Params ) -> Resp + ' static + Send + Sync ,
248
- Req : TryFromRequest + ' static + Send ,
249
- Req :: Error : IntoResponse + Send + ' static ,
250
- Resp : IntoResponse + ' static + Send ,
247
+ F : Fn ( Req , Params ) -> Resp + ' static ,
248
+ Req : TryFromRequest + ' static ,
249
+ Req :: Error : IntoResponse + ' static ,
250
+ Resp : IntoResponse + ' static ,
251
251
{
252
252
self . add ( path, Method :: Get , handler)
253
253
}
254
254
255
255
/// Register an async handler at the path for the HTTP GET method.
256
256
pub fn get_async < F , Fut , Req , Resp > ( & mut self , path : & str , handler : F )
257
257
where
258
- F : Fn ( Req , Params ) -> Fut + ' static + Send + Sync ,
259
- Fut : Future < Output = Resp > + Send + ' static ,
260
- Req : TryFromRequest + ' static + Send ,
261
- Req :: Error : IntoResponse + Send + ' static ,
262
- Resp : IntoResponse + ' static + Send ,
258
+ F : Fn ( Req , Params ) -> Fut + ' static ,
259
+ Fut : Future < Output = Resp > + ' static ,
260
+ Req : TryFromRequest + ' static ,
261
+ Req :: Error : IntoResponse + ' static ,
262
+ Resp : IntoResponse + ' static ,
263
263
{
264
264
self . add_async ( path, Method :: Get , handler)
265
265
}
266
266
267
267
/// Register a handler at the path for the HTTP HEAD method.
268
268
pub fn head < F , Req , Resp > ( & mut self , path : & str , handler : F )
269
269
where
270
- F : Fn ( Req , Params ) -> Resp + ' static + Send + Sync ,
271
- Req : TryFromRequest + ' static + Send ,
272
- Req :: Error : IntoResponse + Send + ' static ,
273
- Resp : IntoResponse + ' static + Send ,
270
+ F : Fn ( Req , Params ) -> Resp + ' static ,
271
+ Req : TryFromRequest + ' static ,
272
+ Req :: Error : IntoResponse + ' static ,
273
+ Resp : IntoResponse + ' static ,
274
274
{
275
275
self . add ( path, Method :: Head , handler)
276
276
}
277
277
278
278
/// Register an async handler at the path for the HTTP HEAD method.
279
279
pub fn head_async < F , Fut , Req , Resp > ( & mut self , path : & str , handler : F )
280
280
where
281
- F : Fn ( Req , Params ) -> Fut + ' static + Send + Sync ,
282
- Fut : Future < Output = Resp > + Send + ' static ,
283
- Req : TryFromRequest + ' static + Send ,
284
- Req :: Error : IntoResponse + Send + ' static ,
285
- Resp : IntoResponse + ' static + Send ,
281
+ F : Fn ( Req , Params ) -> Fut + ' static ,
282
+ Fut : Future < Output = Resp > + ' static ,
283
+ Req : TryFromRequest + ' static ,
284
+ Req :: Error : IntoResponse + ' static ,
285
+ Resp : IntoResponse + ' static ,
286
286
{
287
287
self . add_async ( path, Method :: Head , handler)
288
288
}
289
289
290
290
/// Register a handler at the path for the HTTP POST method.
291
291
pub fn post < F , Req , Resp > ( & mut self , path : & str , handler : F )
292
292
where
293
- F : Fn ( Req , Params ) -> Resp + ' static + Send + Sync ,
294
- Req : TryFromRequest + ' static + Send ,
295
- Req :: Error : IntoResponse + Send + ' static ,
296
- Resp : IntoResponse + ' static + Send ,
293
+ F : Fn ( Req , Params ) -> Resp + ' static ,
294
+ Req : TryFromRequest + ' static ,
295
+ Req :: Error : IntoResponse + ' static ,
296
+ Resp : IntoResponse + ' static ,
297
297
{
298
298
self . add ( path, Method :: Post , handler)
299
299
}
300
300
301
301
/// Register an async handler at the path for the HTTP POST method.
302
302
pub fn post_async < F , Fut , Req , Resp > ( & mut self , path : & str , handler : F )
303
303
where
304
- F : Fn ( Req , Params ) -> Fut + ' static + Send + Sync ,
305
- Fut : Future < Output = Resp > + Send + ' static ,
306
- Req : TryFromRequest + ' static + Send ,
307
- Req :: Error : IntoResponse + Send + ' static ,
308
- Resp : IntoResponse + ' static + Send ,
304
+ F : Fn ( Req , Params ) -> Fut + ' static ,
305
+ Fut : Future < Output = Resp > + ' static ,
306
+ Req : TryFromRequest + ' static ,
307
+ Req :: Error : IntoResponse + ' static ,
308
+ Resp : IntoResponse + ' static ,
309
309
{
310
310
self . add_async ( path, Method :: Post , handler)
311
311
}
312
312
313
313
/// Register a handler at the path for the HTTP DELETE method.
314
314
pub fn delete < F , Req , Resp > ( & mut self , path : & str , handler : F )
315
315
where
316
- F : Fn ( Req , Params ) -> Resp + ' static + Send + Sync ,
317
- Req : TryFromRequest + ' static + Send ,
318
- Req :: Error : IntoResponse + Send + ' static ,
319
- Resp : IntoResponse + ' static + Send ,
316
+ F : Fn ( Req , Params ) -> Resp + ' static ,
317
+ Req : TryFromRequest + ' static ,
318
+ Req :: Error : IntoResponse + ' static ,
319
+ Resp : IntoResponse + ' static ,
320
320
{
321
321
self . add ( path, Method :: Delete , handler)
322
322
}
323
323
324
324
/// Register an async handler at the path for the HTTP DELETE method.
325
325
pub fn delete_async < F , Fut , Req , Resp > ( & mut self , path : & str , handler : F )
326
326
where
327
- F : Fn ( Req , Params ) -> Fut + ' static + Send + Sync ,
328
- Fut : Future < Output = Resp > + Send + ' static ,
329
- Req : TryFromRequest + ' static + Send ,
330
- Req :: Error : IntoResponse + Send + ' static ,
331
- Resp : IntoResponse + ' static + Send ,
327
+ F : Fn ( Req , Params ) -> Fut + ' static ,
328
+ Fut : Future < Output = Resp > + ' static ,
329
+ Req : TryFromRequest + ' static ,
330
+ Req :: Error : IntoResponse + ' static ,
331
+ Resp : IntoResponse + ' static ,
332
332
{
333
333
self . add_async ( path, Method :: Delete , handler)
334
334
}
335
335
336
336
/// Register a handler at the path for the HTTP PUT method.
337
337
pub fn put < F , Req , Resp > ( & mut self , path : & str , handler : F )
338
338
where
339
- F : Fn ( Req , Params ) -> Resp + ' static + Send + Sync ,
340
- Req : TryFromRequest + ' static + Send ,
341
- Req :: Error : IntoResponse + Send + ' static ,
342
- Resp : IntoResponse + ' static + Send ,
339
+ F : Fn ( Req , Params ) -> Resp + ' static ,
340
+ Req : TryFromRequest + ' static ,
341
+ Req :: Error : IntoResponse + ' static ,
342
+ Resp : IntoResponse + ' static ,
343
343
{
344
344
self . add ( path, Method :: Put , handler)
345
345
}
346
346
347
347
/// Register an async handler at the path for the HTTP PUT method.
348
348
pub fn put_async < F , Fut , Req , Resp > ( & mut self , path : & str , handler : F )
349
349
where
350
- F : Fn ( Req , Params ) -> Fut + ' static + Send + Sync ,
351
- Fut : Future < Output = Resp > + Send + ' static ,
352
- Req : TryFromRequest + ' static + Send ,
353
- Req :: Error : IntoResponse + Send + ' static ,
354
- Resp : IntoResponse + ' static + Send ,
350
+ F : Fn ( Req , Params ) -> Fut + ' static ,
351
+ Fut : Future < Output = Resp > + ' static ,
352
+ Req : TryFromRequest + ' static ,
353
+ Req :: Error : IntoResponse + ' static ,
354
+ Resp : IntoResponse + ' static ,
355
355
{
356
356
self . add_async ( path, Method :: Put , handler)
357
357
}
358
358
359
359
/// Register a handler at the path for the HTTP PATCH method.
360
360
pub fn patch < F , Req , Resp > ( & mut self , path : & str , handler : F )
361
361
where
362
- F : Fn ( Req , Params ) -> Resp + ' static + Send + Sync ,
363
- Req : TryFromRequest + ' static + Send ,
364
- Req :: Error : IntoResponse + Send + ' static ,
365
- Resp : IntoResponse + ' static + Send ,
362
+ F : Fn ( Req , Params ) -> Resp + ' static ,
363
+ Req : TryFromRequest + ' static ,
364
+ Req :: Error : IntoResponse + ' static ,
365
+ Resp : IntoResponse + ' static ,
366
366
{
367
367
self . add ( path, Method :: Patch , handler)
368
368
}
369
369
370
370
/// Register an async handler at the path for the HTTP PATCH method.
371
371
pub fn patch_async < F , Fut , Req , Resp > ( & mut self , path : & str , handler : F )
372
372
where
373
- F : Fn ( Req , Params ) -> Fut + ' static + Send + Sync ,
374
- Fut : Future < Output = Resp > + Send + ' static ,
375
- Req : TryFromRequest + ' static + Send ,
376
- Req :: Error : IntoResponse + Send + ' static ,
377
- Resp : IntoResponse + ' static + Send ,
373
+ F : Fn ( Req , Params ) -> Fut + ' static ,
374
+ Fut : Future < Output = Resp > + ' static ,
375
+ Req : TryFromRequest + ' static ,
376
+ Req :: Error : IntoResponse + ' static ,
377
+ Resp : IntoResponse + ' static ,
378
378
{
379
379
self . add_async ( path, Method :: Patch , handler)
380
380
}
381
381
382
382
/// Register a handler at the path for the HTTP OPTIONS method.
383
383
pub fn options < F , Req , Resp > ( & mut self , path : & str , handler : F )
384
384
where
385
- F : Fn ( Req , Params ) -> Resp + ' static + Send + Sync ,
386
- Req : TryFromRequest + ' static + Send ,
387
- Req :: Error : IntoResponse + Send + ' static ,
388
- Resp : IntoResponse + ' static + Send ,
385
+ F : Fn ( Req , Params ) -> Resp + ' static ,
386
+ Req : TryFromRequest + ' static ,
387
+ Req :: Error : IntoResponse + ' static ,
388
+ Resp : IntoResponse + ' static ,
389
389
{
390
390
self . add ( path, Method :: Options , handler)
391
391
}
392
392
393
393
/// Register an async handler at the path for the HTTP OPTIONS method.
394
394
pub fn options_async < F , Fut , Req , Resp > ( & mut self , path : & str , handler : F )
395
395
where
396
- F : Fn ( Req , Params ) -> Fut + ' static + Send + Sync ,
397
- Fut : Future < Output = Resp > + Send + ' static ,
398
- Req : TryFromRequest + ' static + Send ,
399
- Req :: Error : IntoResponse + Send + ' static ,
400
- Resp : IntoResponse + ' static + Send ,
396
+ F : Fn ( Req , Params ) -> Fut + ' static ,
397
+ Fut : Future < Output = Resp > + ' static ,
398
+ Req : TryFromRequest + ' static ,
399
+ Req :: Error : IntoResponse + ' static ,
400
+ Resp : IntoResponse + ' static ,
401
401
{
402
402
self . add_async ( path, Method :: Options , handler)
403
403
}
0 commit comments