11//! Additional handler utilities.
22
3+ use axum:: body:: Body ;
34use axum:: {
45 extract:: FromRequest ,
56 handler:: Handler ,
@@ -19,15 +20,15 @@ pub use self::or::Or;
1920///
2021/// The drawbacks of this trait is that you cannot apply middleware to individual handlers like you
2122/// can with [`Handler::layer`].
22- pub trait HandlerCallWithExtractors < T , S , B > : Sized {
23+ pub trait HandlerCallWithExtractors < T , S > : Sized {
2324 /// The type of future calling this handler returns.
2425 type Future : Future < Output = Response > + Send + ' static ;
2526
2627 /// Call the handler with the extracted inputs.
27- fn call ( self , extractors : T , state : S ) -> <Self as HandlerCallWithExtractors < T , S , B > >:: Future ;
28+ fn call ( self , extractors : T , state : S ) -> <Self as HandlerCallWithExtractors < T , S > >:: Future ;
2829
2930 /// Conver this `HandlerCallWithExtractors` into [`Handler`].
30- fn into_handler ( self ) -> IntoHandler < Self , T , S , B > {
31+ fn into_handler ( self ) -> IntoHandler < Self , T , S > {
3132 IntoHandler {
3233 handler : self ,
3334 _marker : PhantomData ,
@@ -102,9 +103,9 @@ pub trait HandlerCallWithExtractors<T, S, B>: Sized {
102103 /// );
103104 /// # let _: Router = app;
104105 /// ```
105- fn or < R , Rt > ( self , rhs : R ) -> Or < Self , R , T , Rt , S , B >
106+ fn or < R , Rt > ( self , rhs : R ) -> Or < Self , R , T , Rt , S >
106107 where
107- R : HandlerCallWithExtractors < Rt , S , B > ,
108+ R : HandlerCallWithExtractors < Rt , S > ,
108109 {
109110 Or {
110111 lhs : self ,
@@ -117,7 +118,7 @@ pub trait HandlerCallWithExtractors<T, S, B>: Sized {
117118macro_rules! impl_handler_call_with {
118119 ( $( $ty: ident) ,* $( , ) ? ) => {
119120 #[ allow( non_snake_case) ]
120- impl <F , Fut , S , B , $( $ty, ) * > HandlerCallWithExtractors <( $( $ty, ) * ) , S , B > for F
121+ impl <F , Fut , S , $( $ty, ) * > HandlerCallWithExtractors <( $( $ty, ) * ) , S > for F
121122 where
122123 F : FnOnce ( $( $ty, ) * ) -> Fut ,
123124 Fut : Future + Send + ' static ,
@@ -130,7 +131,7 @@ macro_rules! impl_handler_call_with {
130131 self ,
131132 ( $( $ty, ) * ) : ( $( $ty, ) * ) ,
132133 _state: S ,
133- ) -> <Self as HandlerCallWithExtractors <( $( $ty, ) * ) , S , B >>:: Future {
134+ ) -> <Self as HandlerCallWithExtractors <( $( $ty, ) * ) , S >>:: Future {
134135 self ( $( $ty, ) * ) . map( IntoResponse :: into_response)
135136 }
136137 }
@@ -159,22 +160,22 @@ impl_handler_call_with!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
159160///
160161/// Created with [`HandlerCallWithExtractors::into_handler`].
161162#[ allow( missing_debug_implementations) ]
162- pub struct IntoHandler < H , T , S , B > {
163+ pub struct IntoHandler < H , T , S > {
163164 handler : H ,
164- _marker : PhantomData < fn ( ) -> ( T , S , B ) > ,
165+ _marker : PhantomData < fn ( ) -> ( T , S ) > ,
165166}
166167
167- impl < H , T , S , B > Handler < T , S , B > for IntoHandler < H , T , S , B >
168+ impl < H , T , S > Handler < T , S > for IntoHandler < H , T , S >
168169where
169- H : HandlerCallWithExtractors < T , S , B > + Clone + Send + ' static ,
170- T : FromRequest < S , B > + Send + ' static ,
170+ H : HandlerCallWithExtractors < T , S > + Clone + Send + ' static ,
171+ T : FromRequest < S > + Send + ' static ,
171172 T :: Rejection : Send ,
172- B : Send + ' static ,
173173 S : Send + Sync + ' static ,
174174{
175175 type Future = BoxFuture < ' static , Response > ;
176176
177- fn call ( self , req : http:: Request < B > , state : S ) -> Self :: Future {
177+ fn call ( self , req : http:: Request < Body > , state : S ) -> Self :: Future {
178+ let req = req. map ( Body :: new) ;
178179 Box :: pin ( async move {
179180 match T :: from_request ( req, & state) . await {
180181 Ok ( t) => self . handler . call ( t, state) . await ,
@@ -184,9 +185,9 @@ where
184185 }
185186}
186187
187- impl < H , T , S , B > Copy for IntoHandler < H , T , S , B > where H : Copy { }
188+ impl < H , T , S > Copy for IntoHandler < H , T , S > where H : Copy { }
188189
189- impl < H , T , S , B > Clone for IntoHandler < H , T , S , B >
190+ impl < H , T , S > Clone for IntoHandler < H , T , S >
190191where
191192 H : Clone ,
192193{
0 commit comments