Skip to content

Commit 56f7dcf

Browse files
Sh4rKdavidbarsky
authored andcommitted
Migrate lambda-runtime-client to Rust 2018 (#36)
* Migrate lambda-runtime-client to Rust 2018 * Require Rust 1.31 as a minimum.
1 parent a8bdf7b commit 56f7dcf

File tree

6 files changed

+15
-20
lines changed

6 files changed

+15
-20
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ before_cache:
99

1010
matrix:
1111
include:
12-
- rust: 1.30.0
12+
- rust: 1.31.0
1313
- rust: stable
1414
- rust: beta
1515
- rust: nightly

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This package makes it easy to run AWS Lambda Functions written in Rust. This wor
1010

1111
## Example function
1212

13-
The code below creates a simple function that receives an event with a `greeting` and `name` field and returns a `GreetingResponse` message for the given name and greeting. Notice: to run these examples, we require a minimum Rust version of 1.30.
13+
The code below creates a simple function that receives an event with a `greeting` and `name` field and returns a `GreetingResponse` message for the given name and greeting. Notice: to run these examples, we require a minimum Rust version of 1.31.
1414

1515
```rust,no_run
1616
extern crate lambda_runtime as lambda;

lambda-runtime-client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "lambda_runtime_client"
33
version = "0.1.0"
44
authors = ["Stefano Buliani", "David Barsky"]
5+
edition = "2018"
56
description = "Client SDK for AWS Lambda's runtime APIs"
67
keywords = ["AWS", "Lambda", "Runtime", "API", "Client"]
78
license = "Apache-2.0"

lambda-runtime-client/src/client.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
use error::{ApiError, ErrorResponse, RuntimeApiError};
1+
use std::{collections::HashMap, fmt};
2+
23
use hyper::{
34
client::HttpConnector,
45
header::{self, HeaderMap, HeaderValue},
56
rt::{Future, Stream},
67
Body, Client, Method, Request, Uri,
78
};
9+
use serde_derive::Deserialize;
810
use serde_json;
9-
use std::{collections::HashMap, fmt};
1011
use tokio::runtime::Runtime;
1112

13+
use crate::error::{ApiError, ErrorResponse, RuntimeApiError};
14+
1215
const RUNTIME_API_VERSION: &str = "2018-06-01";
1316
const API_CONTENT_TYPE: &str = "application/json";
1417
const API_ERROR_CONTENT_TYPE: &str = "application/vnd.aws.lambda.error+json";
@@ -48,7 +51,7 @@ impl LambdaHeaders {
4851
}
4952

5053
impl fmt::Display for LambdaHeaders {
51-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
54+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5255
f.write_str(self.as_str())
5356
}
5457
}
@@ -257,7 +260,7 @@ impl RuntimeClient {
257260
///
258261
/// # Returns
259262
/// A `Result` object containing a bool return value for the call or an `error::ApiError` instance.
260-
pub fn event_error(&self, request_id: &str, e: &RuntimeApiError) -> Result<(), ApiError> {
263+
pub fn event_error(&self, request_id: &str, e: &dyn RuntimeApiError) -> Result<(), ApiError> {
261264
let uri: Uri = format!(
262265
"http://{}/{}/runtime/invocation/{}/error",
263266
self.endpoint, RUNTIME_API_VERSION, request_id
@@ -304,7 +307,7 @@ impl RuntimeClient {
304307
/// # Panics
305308
/// If it cannot send the init error. In this case we panic to force the runtime
306309
/// to restart.
307-
pub fn fail_init(&self, e: &RuntimeApiError) {
310+
pub fn fail_init(&self, e: &dyn RuntimeApiError) {
308311
let uri: Uri = format!("http://{}/{}/runtime/init/error", self.endpoint, RUNTIME_API_VERSION)
309312
.parse()
310313
.expect("Could not generate Runtime URI");

lambda-runtime-client/src/error.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::{env, error::Error, fmt, io, num::ParseIntError, option::Option};
66
use backtrace;
77
use http::{header::ToStrError, uri::InvalidUri};
88
use hyper;
9+
use serde_derive::Serialize;
910
use serde_json;
1011

1112
/// Error type description for the `ErrorResponse` event. This type should be returned
@@ -118,7 +119,7 @@ impl ApiError {
118119
}
119120

120121
impl fmt::Display for ApiError {
121-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
122+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
122123
write!(f, "{}", self.msg)
123124
}
124125
}
@@ -129,7 +130,7 @@ impl Error for ApiError {
129130
&self.msg
130131
}
131132

132-
fn cause(&self) -> Option<&Error> {
133+
fn cause(&self) -> Option<&dyn Error> {
133134
// Generic error, underlying cause isn't tracked.
134135
None
135136
}

lambda-runtime-client/src/lib.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,7 @@
5858
5959
#[macro_use]
6060
extern crate log;
61-
#[macro_use]
62-
extern crate serde_derive;
63-
64-
extern crate backtrace;
65-
extern crate http;
66-
extern crate hyper;
67-
extern crate serde;
68-
extern crate serde_json;
69-
extern crate tokio;
7061

7162
mod client;
7263
pub mod error;
73-
74-
pub use client::*;
64+
pub use crate::client::*;

0 commit comments

Comments
 (0)