@@ -77,6 +77,7 @@ use crate::{
7777} ;
7878use std:: {
7979 future:: Future ,
80+ marker:: PhantomData ,
8081 pin:: Pin ,
8182 task:: { Context as TaskContext , Poll } ,
8283} ;
@@ -87,28 +88,31 @@ pub type Request = http::Request<Body>;
8788/// Functions serving as ALB and API Gateway REST and HTTP API handlers must conform to this type.
8889///
8990/// This can be viewed as a `lambda_runtime::Handler` constrained to `http` crate `Request` and `Response` types
90- pub trait Handler : Sized {
91+ pub trait Handler < ' a > : Sized {
9192 /// The type of Error that this Handler will return
9293 type Error ;
9394 /// The type of Response this Handler will return
9495 type Response : IntoResponse ;
9596 /// The type of Future this Handler will return
96- type Fut : Future < Output = Result < Self :: Response , Self :: Error > > + Send + ' static ;
97+ type Fut : Future < Output = Result < Self :: Response , Self :: Error > > + Send + ' a ;
9798 /// Function used to execute handler behavior
9899 fn call ( & self , event : Request , context : Context ) -> Self :: Fut ;
99100}
100101
101102/// Adapts a [`Handler`](trait.Handler.html) to the `lambda_runtime::run` interface
102- pub fn handler < H : Handler > ( handler : H ) -> Adapter < H > {
103- Adapter { handler }
103+ pub fn handler < ' a , H : Handler < ' a > > ( handler : H ) -> Adapter < ' a , H > {
104+ Adapter {
105+ handler,
106+ _pd : PhantomData ,
107+ }
104108}
105109
106110/// An implementation of `Handler` for a given closure return a `Future` representing the computed response
107- impl < F , R , Fut > Handler for F
111+ impl < ' a , F , R , Fut > Handler < ' a > for F
108112where
109113 F : Fn ( Request , Context ) -> Fut ,
110114 R : IntoResponse ,
111- Fut : Future < Output = Result < R , Error > > + Send + ' static ,
115+ Fut : Future < Output = Result < R , Error > > + Send + ' a ,
112116{
113117 type Response = R ;
114118 type Error = Error ;
@@ -119,12 +123,12 @@ where
119123}
120124
121125#[ doc( hidden) ]
122- pub struct TransformResponse < R , E > {
126+ pub struct TransformResponse < ' a , R , E > {
123127 request_origin : RequestOrigin ,
124- fut : Pin < Box < dyn Future < Output = Result < R , E > > + Send > > ,
128+ fut : Pin < Box < dyn Future < Output = Result < R , E > > + Send + ' a > > ,
125129}
126130
127- impl < R , E > Future for TransformResponse < R , E >
131+ impl < ' a , R , E > Future for TransformResponse < ' a , R , E >
128132where
129133 R : IntoResponse ,
130134{
@@ -146,11 +150,12 @@ where
146150///
147151/// See [this article](http://smallcultfollowing.com/babysteps/blog/2015/01/14/little-orphan-impls/)
148152/// for a larger explaination of why this is nessessary
149- pub struct Adapter < H : Handler > {
153+ pub struct Adapter < ' a , H : Handler < ' a > > {
150154 handler : H ,
155+ _pd : PhantomData < & ' a H > ,
151156}
152157
153- impl < H : Handler > Handler for Adapter < H > {
158+ impl < ' a , H : Handler < ' a > > Handler < ' a > for Adapter < ' a , H > {
154159 type Response = H :: Response ;
155160 type Error = H :: Error ;
156161 type Fut = H :: Fut ;
@@ -159,9 +164,9 @@ impl<H: Handler> Handler for Adapter<H> {
159164 }
160165}
161166
162- impl < H : Handler > LambdaHandler < LambdaRequest < ' _ > , LambdaResponse > for Adapter < H > {
167+ impl < ' a , H : Handler < ' a > > LambdaHandler < LambdaRequest < ' a > , LambdaResponse > for Adapter < ' a , H > {
163168 type Error = H :: Error ;
164- type Fut = TransformResponse < H :: Response , Self :: Error > ;
169+ type Fut = TransformResponse < ' a , H :: Response , Self :: Error > ;
165170
166171 fn call ( & self , event : LambdaRequest < ' _ > , context : Context ) -> Self :: Fut {
167172 let request_origin = event. request_origin ( ) ;
0 commit comments