diff --git a/.rustfmt.toml b/.rustfmt.toml index dd9156ed..4df947e3 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1,2 +1,4 @@ +# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#merge_imports merge_imports = true +# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#max_width max_width = 120 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 36b2c818..e3373475 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,12 @@ cache: before_cache: - rm -rf /home/travis/.cargo/registry +install: | + # this project's rustfmt style requires nightly features + if [[ "$TRAVIS_RUST_VERSION" == nightly ]]; then + rustup component add rustfmt + fi + matrix: include: - rust: 1.31.0 @@ -18,5 +24,9 @@ matrix: - env: TARGET=x86_64-unknown-linux-musl - env: TARGET=x86_64-unknown-linux-gnu script: + - | + if [[ "$TRAVIS_RUST_VERSION" == nightly ]]; then + cargo fmt --all -- --check + fi - cargo build --verbose --all - cargo test --verbose --all diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 82755c6b..0a293ae8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,9 +1,9 @@ # Contributing Guidelines -Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional +Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional documentation, we greatly value feedback and contributions from our community. -Please read through this document before submitting any issues or pull requests to ensure we have all the necessary +Please read through this document before submitting any issues or pull requests to ensure we have all the necessary information to effectively respond to your bug report or contribution. @@ -11,7 +11,7 @@ information to effectively respond to your bug report or contribution. We welcome you to use the GitHub issue tracker to report bugs or suggest features. -When filing an issue, please check [existing open](https://github.com/awslabs/aws-lambda-rust-runtime/issues), or [recently closed](https://github.com/awslabs/aws-lambda-rust-runtime/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already +When filing an issue, please check [existing open](https://github.com/awslabs/aws-lambda-rust-runtime/issues), or [recently closed](https://github.com/awslabs/aws-lambda-rust-runtime/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: * A reproducible test case or series of steps @@ -32,21 +32,21 @@ To send us a pull request, please: 1. Fork the repository. 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 3. Ensure local tests pass. -4. Commit to your fork using clear commit messages. +4. Commit to your fork using clear commit messages and ensure any Rust source files have been formatted with the [rustfmt tool](https://github.com/rust-lang/rustfmt#quick-start) 5. Send us a pull request, answering any default questions in the pull request interface. 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. -GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and +GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). ## Finding contributions to work on -Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/awslabs/aws-lambda-rust-runtime/labels/help%20wanted) issues is a great place to start. +Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/awslabs/aws-lambda-rust-runtime/labels/help%20wanted) issues is a great place to start. ## Code of Conduct -This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). -For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact +This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). +For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact opensource-codeofconduct@amazon.com with any additional questions or comments. diff --git a/lambda-http/src/ext.rs b/lambda-http/src/ext.rs index a11f0cab..2e52ba16 100644 --- a/lambda-http/src/ext.rs +++ b/lambda-http/src/ext.rs @@ -6,8 +6,7 @@ use serde::{de::value::Error as SerdeError, Deserialize}; use serde_json; use serde_urlencoded; -use crate::request::RequestContext; -use crate::strmap::StrMap; +use crate::{request::RequestContext, strmap::StrMap}; /// API gateway pre-parsed http query string parameters pub(crate) struct QueryStringParameters(pub(crate) StrMap); @@ -157,9 +156,7 @@ mod tests { use serde_derive::Deserialize; use std::collections::HashMap; - use crate::GatewayRequest; - use crate::RequestExt; - use crate::StrMap; + use crate::{GatewayRequest, RequestExt, StrMap}; #[test] fn requests_have_query_string_ext() { diff --git a/lambda-http/src/lib.rs b/lambda-http/src/lib.rs index 049a3b61..8014a0fd 100644 --- a/lambda-http/src/lib.rs +++ b/lambda-http/src/lib.rs @@ -55,12 +55,8 @@ pub mod request; mod response; mod strmap; -pub use crate::body::Body; -pub use crate::ext::RequestExt; -use crate::request::GatewayRequest; -use crate::response::GatewayResponse; -pub use crate::response::IntoResponse; -pub use crate::strmap::StrMap; +pub use crate::{body::Body, ext::RequestExt, response::IntoResponse, strmap::StrMap}; +use crate::{request::GatewayRequest, response::GatewayResponse}; /// Type alias for `http::Request`s with a fixed `lambda_http::Body` body pub type Request = http::Request; diff --git a/lambda-http/src/request.rs b/lambda-http/src/request.rs index cbd1ff08..a52e1acd 100644 --- a/lambda-http/src/request.rs +++ b/lambda-http/src/request.rs @@ -15,9 +15,11 @@ use serde::{ use serde_derive::Deserialize; use serde_json::Value; -use crate::body::Body; -use crate::ext::{PathParameters, QueryStringParameters, StageVariables}; -use crate::strmap::StrMap; +use crate::{ + body::Body, + ext::{PathParameters, QueryStringParameters, StageVariables}, + strmap::StrMap, +}; /// Representation of an API Gateway proxy event data #[doc(hidden)] diff --git a/lambda-runtime/src/context.rs b/lambda-runtime/src/context.rs index aef26e96..0c78a916 100644 --- a/lambda-runtime/src/context.rs +++ b/lambda-runtime/src/context.rs @@ -4,8 +4,7 @@ use backtrace; use chrono::Utc; use lambda_runtime_client; -use crate::env as lambda_env; -use crate::error::HandlerError; +use crate::{env as lambda_env, error::HandlerError}; /// The Lambda function execution context. The values in this struct /// are populated using the [Lambda environment variables](https://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html) diff --git a/lambda-runtime/src/env.rs b/lambda-runtime/src/env.rs index 4a94587c..7c55a2bd 100644 --- a/lambda-runtime/src/env.rs +++ b/lambda-runtime/src/env.rs @@ -88,8 +88,7 @@ impl ConfigProvider for EnvConfigProvider { #[cfg(test)] pub(crate) mod tests { - use crate::env::*; - use crate::error; + use crate::{env::*, error}; use std::{env, error::Error}; pub(crate) struct MockConfigProvider { diff --git a/lambda-runtime/src/lib.rs b/lambda-runtime/src/lib.rs index 88e19ce9..5bf22c1d 100644 --- a/lambda-runtime/src/lib.rs +++ b/lambda-runtime/src/lib.rs @@ -83,6 +83,4 @@ mod env; pub mod error; mod runtime; -pub use crate::context::*; -pub use crate::error::HandlerError; -pub use crate::runtime::*; +pub use crate::{context::*, error::HandlerError, runtime::*}; diff --git a/lambda-runtime/src/runtime.rs b/lambda-runtime/src/runtime.rs index cc55e33f..caac0983 100644 --- a/lambda-runtime/src/runtime.rs +++ b/lambda-runtime/src/runtime.rs @@ -5,9 +5,11 @@ use serde; use serde_json; use tokio::runtime::Runtime as TokioRuntime; -use crate::context::Context; -use crate::env::{ConfigProvider, EnvConfigProvider, FunctionSettings}; -use crate::error::{HandlerError, RuntimeError}; +use crate::{ + context::Context, + env::{ConfigProvider, EnvConfigProvider, FunctionSettings}, + error::{HandlerError, RuntimeError}, +}; const MAX_RETRIES: i8 = 3; @@ -323,8 +325,7 @@ where #[cfg(test)] pub(crate) mod tests { use super::*; - use crate::context; - use crate::env; + use crate::{context, env}; use lambda_runtime_client::RuntimeClient; #[test]