1
1
use std:: { error:: Error , result} ;
2
2
3
- use lambda_runtime_client;
4
3
use serde;
5
4
use serde_json;
6
5
6
+ use lambda_runtime_client:: RuntimeClient ;
7
7
use context:: Context ;
8
8
use env:: { ConfigProvider , EnvConfigProvider , FunctionSettings } ;
9
9
use error:: { HandlerError , RuntimeError } ;
@@ -22,12 +22,12 @@ pub type Handler<E, O> = fn(E, Context) -> Result<O, HandlerError>;
22
22
///
23
23
/// # Panics
24
24
/// The function panics if the Lambda environment variables are not set.
25
- pub fn start < E : ' static , O : ' static > ( f : Handler < E , O > , runtime : Option < TokioRuntime > )
25
+ pub fn start < E , O > ( f : Handler < E , O > , runtime : Option < TokioRuntime > )
26
26
where
27
27
for < ' invocation > E : serde:: Deserialize < ' invocation > ,
28
28
O : serde:: Serialize ,
29
29
{
30
- start_with_config ( f, & EnvConfigProvider { } , runtime)
30
+ start_with_config ( f, EnvConfigProvider :: new ( ) , runtime)
31
31
}
32
32
33
33
#[ macro_export]
@@ -53,13 +53,14 @@ macro_rules! lambda {
53
53
/// The function panics if the `ConfigProvider` returns an error from the `get_runtime_api_endpoint()`
54
54
/// or `get_function_settings()` methods. The panic forces AWS Lambda to terminate the environment
55
55
/// and spin up a new one for the next invocation.
56
- pub ( crate ) fn start_with_config < E : ' static , O : ' static > (
56
+ pub ( crate ) fn start_with_config < E , O , C > (
57
57
f : Handler < E , O > ,
58
- config : & ' static ConfigProvider ,
58
+ config : C ,
59
59
runtime : Option < TokioRuntime > ,
60
60
) where
61
61
for < ' invocation > E : serde:: Deserialize < ' invocation > ,
62
62
O : serde:: Serialize ,
63
+ C : ConfigProvider ,
63
64
{
64
65
// if we cannot find the endpoint we panic, nothing else we can do.
65
66
let endpoint: String ;
@@ -81,10 +82,9 @@ pub(crate) fn start_with_config<E: 'static, O: 'static>(
81
82
}
82
83
}
83
84
84
- match lambda_runtime_client :: HttpRuntimeClient :: new ( endpoint, runtime) {
85
+ match RuntimeClient :: new ( endpoint, runtime) {
85
86
Ok ( client) => {
86
- let trait_client: & lambda_runtime_client:: RuntimeClient = & client;
87
- start_with_runtime_client ( f, function_config, trait_client) ;
87
+ start_with_runtime_client ( f, function_config, client) ;
88
88
}
89
89
Err ( e) => {
90
90
panic ! ( "Could not create runtime client SDK: {}" , e) ;
@@ -103,10 +103,10 @@ pub(crate) fn start_with_config<E: 'static, O: 'static>(
103
103
///
104
104
/// # Panics
105
105
/// The function panics if we cannot instantiate a new `RustRuntime` object.
106
- pub ( crate ) fn start_with_runtime_client < ' env , E : ' static , O : ' static > (
106
+ pub ( crate ) fn start_with_runtime_client < E , O > (
107
107
f : Handler < E , O > ,
108
108
func_settings : FunctionSettings ,
109
- client : & ' env lambda_runtime_client :: RuntimeClient ,
109
+ client : RuntimeClient ,
110
110
) where
111
111
for < ' invocation > E : serde:: Deserialize < ' invocation > ,
112
112
O : serde:: Serialize ,
@@ -125,15 +125,15 @@ pub(crate) fn start_with_runtime_client<'env, E: 'static, O: 'static>(
125
125
126
126
/// Internal representation of the runtime object that polls for events and communicates
127
127
/// with the Runtime APIs
128
- pub ( super ) struct Runtime < ' env , E : ' static , O : ' static > {
129
- runtime_client : & ' env lambda_runtime_client :: RuntimeClient ,
128
+ pub ( super ) struct Runtime < E , O > {
129
+ runtime_client : RuntimeClient ,
130
130
handler : Handler < E , O > ,
131
131
max_retries : i8 ,
132
132
settings : FunctionSettings ,
133
133
}
134
134
135
135
// generic methods implementation
136
- impl < ' env , E , O > Runtime < ' env , E , O > {
136
+ impl < E , O > Runtime < E , O > {
137
137
/// Creates a new instance of the `Runtime` object populated with the environment
138
138
/// settings.
139
139
///
@@ -151,8 +151,8 @@ impl<'env, E, O> Runtime<'env, E, O> {
151
151
f : Handler < E , O > ,
152
152
config : FunctionSettings ,
153
153
retries : i8 ,
154
- client : & ' env lambda_runtime_client :: RuntimeClient ,
155
- ) -> result:: Result < Runtime < ' env , E , O > , RuntimeError > {
154
+ client : RuntimeClient ,
155
+ ) -> result:: Result < Runtime < E , O > , RuntimeError > {
156
156
debug ! (
157
157
"Creating new runtime with {} max retries for endpoint {}" ,
158
158
retries,
@@ -169,7 +169,7 @@ impl<'env, E, O> Runtime<'env, E, O> {
169
169
170
170
// implementation of methods that require the Event and Output types
171
171
// to be compatible with `serde`'s Deserialize/Serialize.
172
- impl < ' env , E , O > Runtime < ' env , E , O >
172
+ impl < ' env , E , O > Runtime < E , O >
173
173
where
174
174
for < ' de > E : serde:: Deserialize < ' de > ,
175
175
O : serde:: Serialize ,
@@ -300,12 +300,12 @@ pub(crate) mod tests {
300
300
use super :: * ;
301
301
use context;
302
302
use env;
303
- use lambda_runtime_client as cli ;
303
+ use lambda_runtime_client:: RuntimeClient ;
304
304
305
305
#[ test]
306
306
fn runtime_invokes_handler ( ) {
307
307
let config: & env:: ConfigProvider = & env:: tests:: MockConfigProvider { error : false } ;
308
- let client: & lambda_runtime_client :: RuntimeClient = & cli :: HttpRuntimeClient :: new (
308
+ let client = RuntimeClient :: new (
309
309
config
310
310
. get_runtime_api_endpoint ( )
311
311
. expect ( "Could not get runtime endpoint" ) ,
0 commit comments