diff --git a/Cargo.lock b/Cargo.lock index 6e8f9d85..49c98444 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,10 +1,5 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -[[package]] -name = "anyhow" -version = "1.0.28" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "arc-swap" version = "0.4.4" @@ -286,7 +281,6 @@ dependencies = [ name = "lambda" version = "0.1.0" dependencies = [ - "anyhow 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "genawaiter 0.99.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -851,7 +845,6 @@ dependencies = [ ] [metadata] -"checksum anyhow 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "d9a60d744a80c30fcb657dfe2c1b22bcb3e814c1a1e3674f32bf5820b570fbff" "checksum arc-swap 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d7b8a9123b8027467bce0099fe556c628a53c8d83df0507084c31e9ba2e39aff" "checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" "checksum base64 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "53d1ccbaf7d9ec9537465a97bf19edc1a4e158ecb49fc16178202238c569cc42" diff --git a/lambda-http/examples/basic.rs b/lambda-http/examples/hello-http-without-macros.rs similarity index 100% rename from lambda-http/examples/basic.rs rename to lambda-http/examples/hello-http-without-macros.rs diff --git a/lambda-http/examples/hello.rs b/lambda-http/examples/hello-http.rs similarity index 100% rename from lambda-http/examples/hello.rs rename to lambda-http/examples/hello-http.rs diff --git a/lambda-http/src/lib.rs b/lambda-http/src/lib.rs index bca6287a..077356bf 100644 --- a/lambda-http/src/lib.rs +++ b/lambda-http/src/lib.rs @@ -23,6 +23,7 @@ //! //! ```rust,no_run //! use lambda_http::{lambda, Request, IntoResponse}; +//! //! type Error = Box; //! //! #[lambda(http)] @@ -40,6 +41,7 @@ //! //! ```rust,no_run //! use lambda_http::{handler, lambda}; +//! //! type Error = Box; //! //! #[tokio::main] @@ -59,6 +61,7 @@ //! //! ```rust,no_run //! use lambda_http::{handler, lambda, IntoResponse, Request, RequestExt}; +//! //! type Error = Box; //! //! #[tokio::main] @@ -89,7 +92,7 @@ pub use http::{self, Response}; use lambda::Handler as LambdaHandler; pub use lambda::{self}; pub use lambda_attributes::lambda; -//pub use lambda_http_attributes::lambda_http; + mod body; pub mod ext; pub mod request; @@ -98,14 +101,13 @@ mod strmap; pub use crate::{body::Body, ext::RequestExt, response::IntoResponse, strmap::StrMap}; use crate::{request::LambdaRequest, response::LambdaResponse}; use std::{ - error::Error, - fmt, future::Future, pin::Pin, task::{Context, Poll}, }; -type Err = Box; +/// Error type that lambdas may result in +pub(crate) type Error = Box; /// Type alias for `http::Request`s with a fixed [`Body`](enum.Body.html) type pub type Request = http::Request; @@ -134,11 +136,10 @@ impl Handler for F where F: FnMut(Request) -> Fut, R: IntoResponse, - Fut: Future> + Send + 'static, - Err: Into> + fmt::Debug, + Fut: Future> + Send + 'static, { type Response = R; - type Error = Err; + type Error = Error; type Fut = Fut; fn call(&mut self, event: Request) -> Self::Fut { (*self)(event) diff --git a/lambda/Cargo.toml b/lambda/Cargo.toml index b3b82041..7acf8cbd 100644 --- a/lambda/Cargo.toml +++ b/lambda/Cargo.toml @@ -25,4 +25,3 @@ futures = "0.3" tracing = "0.1.13" tracing-futures = "0.2.3" tracing-error = "0.1.2" -anyhow = "1.0.27" diff --git a/lambda/src/client.rs b/lambda/src/client.rs index 7bc833a2..64313ebf 100644 --- a/lambda/src/client.rs +++ b/lambda/src/client.rs @@ -1,5 +1,7 @@ -use crate::requests::{IntoResponse, NextEventResponse}; -use anyhow::Error; +use crate::{ + requests::{IntoResponse, NextEventResponse}, + Error, +}; use http::{ uri::{PathAndQuery, Scheme}, HeaderValue, Method, Request, Response, StatusCode, Uri, @@ -172,8 +174,8 @@ mod endpoint_tests { requests::{EventCompletionRequest, EventErrorRequest, IntoRequest, NextEventRequest}, simulated::SimulatedConnector, types::Diagnostic, + Error, }; - use anyhow::Error; use http::{HeaderValue, StatusCode, Uri}; use std::convert::TryFrom; use tokio::sync; @@ -203,7 +205,7 @@ mod endpoint_tests { tx.send(()).expect("Receiver has been dropped"); match server.await { Ok(_) => Ok(()), - Err(e) if e.is_panic() => return Err::<(), anyhow::Error>(e.into()), + Err(e) if e.is_panic() => return Err::<(), Error>(e.into()), Err(_) => unreachable!("This branch shouldn't be reachable"), } } @@ -235,7 +237,7 @@ mod endpoint_tests { tx.send(()).expect("Receiver has been dropped"); match server.await { Ok(_) => Ok(()), - Err(e) if e.is_panic() => return Err::<(), anyhow::Error>(e.into()), + Err(e) if e.is_panic() => return Err::<(), Error>(e.into()), Err(_) => unreachable!("This branch shouldn't be reachable"), } } @@ -269,7 +271,7 @@ mod endpoint_tests { tx.send(()).expect("Receiver has been dropped"); match server.await { Ok(_) => Ok(()), - Err(e) if e.is_panic() => return Err::<(), anyhow::Error>(e.into()), + Err(e) if e.is_panic() => return Err::<(), Error>(e.into()), Err(_) => unreachable!("This branch shouldn't be reachable"), } } diff --git a/lambda/src/lib.rs b/lambda/src/lib.rs index 0c76f78f..17067d83 100644 --- a/lambda/src/lib.rs +++ b/lambda/src/lib.rs @@ -25,7 +25,7 @@ //! of [`lambda::LambdaCtx`]. //! //! ```no_run -//! use lambda::lambda; +//! use lambda::{lambda}; //! use serde_json::Value; //! //! type Error = Box; @@ -37,7 +37,6 @@ //! } //! ``` pub use crate::types::LambdaCtx; -use anyhow::Error; use client::Client; use futures::stream::{Stream, StreamExt}; use genawaiter::{sync::gen, yield_}; @@ -58,6 +57,9 @@ mod types; use requests::{EventCompletionRequest, EventErrorRequest, IntoRequest, NextEventRequest}; use types::Diagnostic; +/// Error type that lambdas may result in +pub(crate) type Error = Box; + /// Configuration derived from environment variables. #[derive(Debug, Default, Clone, PartialEq)] pub struct Config { @@ -119,7 +121,7 @@ impl Handler for HandlerFn where F: Fn(A) -> Fut, Fut: Future> + Send, - Error: Into> + fmt::Debug, + Error: Into + fmt::Debug, { type Error = Error; type Fut = Fut; @@ -134,7 +136,7 @@ where /// /// # Example /// ```no_run -/// use lambda::handler_fn; +/// use lambda::{handler_fn}; /// use serde_json::Value; /// /// type Error = Box; diff --git a/lambda/src/requests.rs b/lambda/src/requests.rs index 4eabc3c1..2d691b94 100644 --- a/lambda/src/requests.rs +++ b/lambda/src/requests.rs @@ -1,5 +1,4 @@ -use crate::types::Diagnostic; -use anyhow::Error; +use crate::{types::Diagnostic, Error}; use http::{Method, Request, Response, Uri}; use hyper::Body; use serde::Serialize; diff --git a/lambda/src/types.rs b/lambda/src/types.rs index b744cd46..2efcb3d1 100644 --- a/lambda/src/types.rs +++ b/lambda/src/types.rs @@ -1,5 +1,4 @@ -use crate::Config; -use anyhow::Error; +use crate::{Config, Error}; use http::HeaderMap; use serde::{Deserialize, Serialize}; use std::{collections::HashMap, convert::TryFrom};