@@ -6,7 +6,7 @@ use tower::util::BoxCloneSyncService;
66
77use crate :: request:: Request ;
88use crate :: request:: extractors:: { FromRequest , FromRequestParts } ;
9- use crate :: response:: Response ;
9+ use crate :: response:: { IntoResponse , Response } ;
1010use crate :: { Error , Result } ;
1111
1212/// A function that takes a request and returns a response.
@@ -59,11 +59,12 @@ pub(crate) fn into_box_request_handler<T, H: RequestHandler<T> + Send + Sync>(
5959
6060macro_rules! impl_request_handler {
6161 ( $( $ty: ident) ,* ) => {
62- impl <T , $( $ty, ) * R > RequestHandler <( $( $ty, ) * ) > for T
62+ impl <Func , $( $ty, ) * Fut , R > RequestHandler <( $( $ty, ) * ) > for Func
6363 where
64- T : FnOnce ( $( $ty, ) * ) -> R + Clone + Send + Sync + ' static ,
64+ Func : FnOnce ( $( $ty, ) * ) -> Fut + Clone + Send + Sync + ' static ,
6565 $( $ty: FromRequestParts + Send , ) *
66- R : for <' a> Future <Output = Result <Response >> + Send ,
66+ Fut : Future <Output = R > + Send ,
67+ R : IntoResponse ,
6768 {
6869 #[ allow( non_snake_case) ]
6970 async fn handle( & self , request: Request ) -> Result <Response > {
@@ -74,21 +75,22 @@ macro_rules! impl_request_handler {
7475 let $ty = $ty:: from_request_parts( & mut parts) . await ?;
7576 ) *
7677
77- self . clone( ) ( $( $ty, ) * ) . await
78+ self . clone( ) ( $( $ty, ) * ) . await . into_response ( )
7879 }
7980 }
8081 } ;
8182}
8283
8384macro_rules! impl_request_handler_from_request {
8485 ( $( $ty_lhs: ident, ) * ( $ty_from_request: ident) $( , $ty_rhs: ident) * ) => {
85- impl <T , $( $ty_lhs, ) * $ty_from_request, $( $ty_rhs, ) * R > RequestHandler <( $( $ty_lhs, ) * $ty_from_request, ( ) , $( $ty_rhs, ) * ) > for T
86+ impl <Func , $( $ty_lhs, ) * $ty_from_request, $( $ty_rhs, ) * Fut , R > RequestHandler <( $( $ty_lhs, ) * $ty_from_request, ( ) , $( $ty_rhs, ) * ) > for Func
8687 where
87- T : FnOnce ( $( $ty_lhs, ) * $ty_from_request, $( $ty_rhs) ,* ) -> R + Clone + Send + Sync + ' static ,
88+ Func : FnOnce ( $( $ty_lhs, ) * $ty_from_request, $( $ty_rhs) ,* ) -> Fut + Clone + Send + Sync + ' static ,
8889 $( $ty_lhs: FromRequestParts + Send , ) *
8990 $ty_from_request: FromRequest + Send ,
9091 $( $ty_rhs: FromRequestParts + Send , ) *
91- R : for <' a> Future <Output = Result <Response >> + Send ,
92+ Fut : Future <Output = R > + Send ,
93+ R : IntoResponse ,
9294 {
9395 #[ expect( non_snake_case) ]
9496 async fn handle( & self , request: Request ) -> Result <Response > {
@@ -105,79 +107,99 @@ macro_rules! impl_request_handler_from_request {
105107 let request = Request :: from_parts( parts, body) ;
106108 let $ty_from_request = $ty_from_request:: from_request( request) . await ?;
107109
108- self . clone( ) ( $( $ty_lhs, ) * $ty_from_request, $( $ty_rhs) ,* ) . await
110+ self . clone( ) ( $( $ty_lhs, ) * $ty_from_request, $( $ty_rhs) ,* ) . await . into_response ( )
109111 }
110112 }
111113 } ;
112114}
113115
114- impl_request_handler ! ( ) ;
115- impl_request_handler ! ( P1 ) ;
116- impl_request_handler ! ( P1 , P2 ) ;
117- impl_request_handler ! ( P1 , P2 , P3 ) ;
118- impl_request_handler ! ( P1 , P2 , P3 , P4 ) ;
119- impl_request_handler ! ( P1 , P2 , P3 , P4 , P5 ) ;
120- impl_request_handler ! ( P1 , P2 , P3 , P4 , P5 , P6 ) ;
121- impl_request_handler ! ( P1 , P2 , P3 , P4 , P5 , P6 , P7 ) ;
122- impl_request_handler ! ( P1 , P2 , P3 , P4 , P5 , P6 , P7 , P8 ) ;
123- impl_request_handler ! ( P1 , P2 , P3 , P4 , P5 , P6 , P7 , P8 , P9 ) ;
124- impl_request_handler ! ( P1 , P2 , P3 , P4 , P5 , P6 , P7 , P8 , P9 , P10 ) ;
125-
126- impl_request_handler_from_request ! ( ( P1 ) ) ;
127- impl_request_handler_from_request ! ( ( P1 ) , P2 ) ;
128- impl_request_handler_from_request ! ( P1 , ( P2 ) ) ;
129- impl_request_handler_from_request ! ( ( P1 ) , P2 , P3 ) ;
130- impl_request_handler_from_request ! ( P1 , ( P2 ) , P3 ) ;
131- impl_request_handler_from_request ! ( P1 , P2 , ( P3 ) ) ;
132- impl_request_handler_from_request ! ( ( P1 ) , P2 , P3 , P4 ) ;
133- impl_request_handler_from_request ! ( P1 , ( P2 ) , P3 , P4 ) ;
134- impl_request_handler_from_request ! ( P1 , P2 , ( P3 ) , P4 ) ;
135- impl_request_handler_from_request ! ( P1 , P2 , P3 , ( P4 ) ) ;
136- impl_request_handler_from_request ! ( ( P1 ) , P2 , P3 , P4 , P5 ) ;
137- impl_request_handler_from_request ! ( P1 , ( P2 ) , P3 , P4 , P5 ) ;
138- impl_request_handler_from_request ! ( P1 , P2 , ( P3 ) , P4 , P5 ) ;
139- impl_request_handler_from_request ! ( P1 , P2 , P3 , ( P4 ) , P5 ) ;
140- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , ( P5 ) ) ;
141- impl_request_handler_from_request ! ( ( P1 ) , P2 , P3 , P4 , P5 , P6 ) ;
142- impl_request_handler_from_request ! ( P1 , ( P2 ) , P3 , P4 , P5 , P6 ) ;
143- impl_request_handler_from_request ! ( P1 , P2 , ( P3 ) , P4 , P5 , P6 ) ;
144- impl_request_handler_from_request ! ( P1 , P2 , P3 , ( P4 ) , P5 , P6 ) ;
145- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , ( P5 ) , P6 ) ;
146- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , P5 , ( P6 ) ) ;
147- impl_request_handler_from_request ! ( ( P1 ) , P2 , P3 , P4 , P5 , P6 , P7 ) ;
148- impl_request_handler_from_request ! ( P1 , ( P2 ) , P3 , P4 , P5 , P6 , P7 ) ;
149- impl_request_handler_from_request ! ( P1 , P2 , ( P3 ) , P4 , P5 , P6 , P7 ) ;
150- impl_request_handler_from_request ! ( P1 , P2 , P3 , ( P4 ) , P5 , P6 , P7 ) ;
151- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , ( P5 ) , P6 , P7 ) ;
152- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , P5 , ( P6 ) , P7 ) ;
153- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , P5 , P6 , ( P7 ) ) ;
154- impl_request_handler_from_request ! ( ( P1 ) , P2 , P3 , P4 , P5 , P6 , P7 , P8 ) ;
155- impl_request_handler_from_request ! ( P1 , ( P2 ) , P3 , P4 , P5 , P6 , P7 , P8 ) ;
156- impl_request_handler_from_request ! ( P1 , P2 , ( P3 ) , P4 , P5 , P6 , P7 , P8 ) ;
157- impl_request_handler_from_request ! ( P1 , P2 , P3 , ( P4 ) , P5 , P6 , P7 , P8 ) ;
158- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , ( P5 ) , P6 , P7 , P8 ) ;
159- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , P5 , ( P6 ) , P7 , P8 ) ;
160- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , P5 , P6 , ( P7 ) , P8 ) ;
161- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , P5 , P6 , P7 , ( P8 ) ) ;
162- impl_request_handler_from_request ! ( ( P1 ) , P2 , P3 , P4 , P5 , P6 , P7 , P8 , P9 ) ;
163- impl_request_handler_from_request ! ( P1 , ( P2 ) , P3 , P4 , P5 , P6 , P7 , P8 , P9 ) ;
164- impl_request_handler_from_request ! ( P1 , P2 , ( P3 ) , P4 , P5 , P6 , P7 , P8 , P9 ) ;
165- impl_request_handler_from_request ! ( P1 , P2 , P3 , ( P4 ) , P5 , P6 , P7 , P8 , P9 ) ;
166- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , ( P5 ) , P6 , P7 , P8 , P9 ) ;
167- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , P5 , ( P6 ) , P7 , P8 , P9 ) ;
168- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , P5 , P6 , ( P7 ) , P8 , P9 ) ;
169- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , P5 , P6 , P7 , ( P8 ) , P9 ) ;
170- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , P5 , P6 , P7 , P8 , ( P9 ) ) ;
171- impl_request_handler_from_request ! ( ( P1 ) , P2 , P3 , P4 , P5 , P6 , P7 , P8 , P9 , P10 ) ;
172- impl_request_handler_from_request ! ( P1 , ( P2 ) , P3 , P4 , P5 , P6 , P7 , P8 , P9 , P10 ) ;
173- impl_request_handler_from_request ! ( P1 , P2 , ( P3 ) , P4 , P5 , P6 , P7 , P8 , P9 , P10 ) ;
174- impl_request_handler_from_request ! ( P1 , P2 , P3 , ( P4 ) , P5 , P6 , P7 , P8 , P9 , P10 ) ;
175- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , ( P5 ) , P6 , P7 , P8 , P9 , P10 ) ;
176- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , P5 , ( P6 ) , P7 , P8 , P9 , P10 ) ;
177- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , P5 , P6 , ( P7 ) , P8 , P9 , P10 ) ;
178- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , P5 , P6 , P7 , ( P8 ) , P9 , P10 ) ;
179- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , P5 , P6 , P7 , P8 , ( P9 ) , P10 ) ;
180- impl_request_handler_from_request ! ( P1 , P2 , P3 , P4 , P5 , P6 , P7 , P8 , P9 , ( P10 ) ) ;
116+ macro_rules! handle_all_parameters {
117+ ( $name: ident) => {
118+ $name!( ) ;
119+ $name!( P1 ) ;
120+ $name!( P1 , P2 ) ;
121+ $name!( P1 , P2 , P3 ) ;
122+ $name!( P1 , P2 , P3 , P4 ) ;
123+ $name!( P1 , P2 , P3 , P4 , P5 ) ;
124+ $name!( P1 , P2 , P3 , P4 , P5 , P6 ) ;
125+ $name!( P1 , P2 , P3 , P4 , P5 , P6 , P7 ) ;
126+ $name!( P1 , P2 , P3 , P4 , P5 , P6 , P7 , P8 ) ;
127+ $name!( P1 , P2 , P3 , P4 , P5 , P6 , P7 , P8 , P9 ) ;
128+ $name!( P1 , P2 , P3 , P4 , P5 , P6 , P7 , P8 , P9 , P10 ) ;
129+ } ;
130+ }
131+
132+ macro_rules! handle_all_parameters_from_request {
133+ ( $name: ident) => {
134+ $name!( ( PX ) ) ;
135+
136+ $name!( ( PX ) , P2 ) ;
137+ $name!( P1 , ( PX ) ) ;
138+
139+ $name!( ( PX ) , P2 , P3 ) ;
140+ $name!( P1 , ( PX ) , P3 ) ;
141+ $name!( P1 , P2 , ( PX ) ) ;
142+
143+ $name!( ( PX ) , P2 , P3 , P4 ) ;
144+ $name!( P1 , ( PX ) , P3 , P4 ) ;
145+ $name!( P1 , P2 , ( PX ) , P4 ) ;
146+ $name!( P1 , P2 , P3 , ( PX ) ) ;
147+
148+ $name!( ( PX ) , P2 , P3 , P4 , P5 ) ;
149+ $name!( P1 , ( PX ) , P3 , P4 , P5 ) ;
150+ $name!( P1 , P2 , ( PX ) , P4 , P5 ) ;
151+ $name!( P1 , P2 , P3 , ( PX ) , P5 ) ;
152+ $name!( P1 , P2 , P3 , P4 , ( PX ) ) ;
153+
154+ $name!( ( PX ) , P2 , P3 , P4 , P5 , P6 ) ;
155+ $name!( P1 , ( PX ) , P3 , P4 , P5 , P6 ) ;
156+ $name!( P1 , P2 , ( PX ) , P4 , P5 , P6 ) ;
157+ $name!( P1 , P2 , P3 , ( PX ) , P5 , P6 ) ;
158+ $name!( P1 , P2 , P3 , P4 , ( PX ) , P6 ) ;
159+ $name!( P1 , P2 , P3 , P4 , P5 , ( PX ) ) ;
160+
161+ $name!( ( PX ) , P2 , P3 , P4 , P5 , P6 , P7 ) ;
162+ $name!( P1 , ( PX ) , P3 , P4 , P5 , P6 , P7 ) ;
163+ $name!( P1 , P2 , ( PX ) , P4 , P5 , P6 , P7 ) ;
164+ $name!( P1 , P2 , P3 , ( PX ) , P5 , P6 , P7 ) ;
165+ $name!( P1 , P2 , P3 , P4 , ( PX ) , P6 , P7 ) ;
166+ $name!( P1 , P2 , P3 , P4 , P5 , ( PX ) , P7 ) ;
167+ $name!( P1 , P2 , P3 , P4 , P5 , P6 , ( PX ) ) ;
168+
169+ $name!( ( PX ) , P2 , P3 , P4 , P5 , P6 , P7 , P8 ) ;
170+ $name!( P1 , ( PX ) , P3 , P4 , P5 , P6 , P7 , P8 ) ;
171+ $name!( P1 , P2 , ( PX ) , P4 , P5 , P6 , P7 , P8 ) ;
172+ $name!( P1 , P2 , P3 , ( PX ) , P5 , P6 , P7 , P8 ) ;
173+ $name!( P1 , P2 , P3 , P4 , ( PX ) , P6 , P7 , P8 ) ;
174+ $name!( P1 , P2 , P3 , P4 , P5 , ( PX ) , P7 , P8 ) ;
175+ $name!( P1 , P2 , P3 , P4 , P5 , P6 , ( PX ) , P8 ) ;
176+ $name!( P1 , P2 , P3 , P4 , P5 , P6 , P7 , ( PX ) ) ;
177+
178+ $name!( ( PX ) , P2 , P3 , P4 , P5 , P6 , P7 , P8 , P9 ) ;
179+ $name!( P1 , ( PX ) , P3 , P4 , P5 , P6 , P7 , P8 , P9 ) ;
180+ $name!( P1 , P2 , ( PX ) , P4 , P5 , P6 , P7 , P8 , P9 ) ;
181+ $name!( P1 , P2 , P3 , ( PX ) , P5 , P6 , P7 , P8 , P9 ) ;
182+ $name!( P1 , P2 , P3 , P4 , ( PX ) , P6 , P7 , P8 , P9 ) ;
183+ $name!( P1 , P2 , P3 , P4 , P5 , ( PX ) , P7 , P8 , P9 ) ;
184+ $name!( P1 , P2 , P3 , P4 , P5 , P6 , ( PX ) , P8 , P9 ) ;
185+ $name!( P1 , P2 , P3 , P4 , P5 , P6 , P7 , ( PX ) , P9 ) ;
186+ $name!( P1 , P2 , P3 , P4 , P5 , P6 , P7 , P8 , ( PX ) ) ;
187+
188+ $name!( ( PX ) , P2 , P3 , P4 , P5 , P6 , P7 , P8 , P9 , P10 ) ;
189+ $name!( P1 , ( PX ) , P3 , P4 , P5 , P6 , P7 , P8 , P9 , P10 ) ;
190+ $name!( P1 , P2 , ( PX ) , P4 , P5 , P6 , P7 , P8 , P9 , P10 ) ;
191+ $name!( P1 , P2 , P3 , ( PX ) , P5 , P6 , P7 , P8 , P9 , P10 ) ;
192+ $name!( P1 , P2 , P3 , P4 , ( PX ) , P6 , P7 , P8 , P9 , P10 ) ;
193+ $name!( P1 , P2 , P3 , P4 , P5 , ( PX ) , P7 , P8 , P9 , P10 ) ;
194+ $name!( P1 , P2 , P3 , P4 , P5 , P6 , ( PX ) , P8 , P9 , P10 ) ;
195+ $name!( P1 , P2 , P3 , P4 , P5 , P6 , P7 , ( PX ) , P9 , P10 ) ;
196+ $name!( P1 , P2 , P3 , P4 , P5 , P6 , P7 , P8 , ( PX ) , P10 ) ;
197+ $name!( P1 , P2 , P3 , P4 , P5 , P6 , P7 , P8 , P9 , ( P10 ) ) ;
198+ } ;
199+ }
200+
201+ handle_all_parameters ! ( impl_request_handler) ;
202+ handle_all_parameters_from_request ! ( impl_request_handler_from_request) ;
181203
182204/// A wrapper around a handler that's used in
183205/// [`Bootstrapper`](cot::Bootstrapper).
0 commit comments