Skip to content

Commit 96fc5bc

Browse files
authored
Making Error type public so that consumers don't have to create their own type alias (#298)
* Making Error type public so that consumers don't have to create their own type alias * Missed usage in example * Rust fmt changes * Missed example use. * Changing lambda_runtime::Error references to just Error and including in imports instead.
1 parent ad0a1d2 commit 96fc5bc

File tree

4 files changed

+6
-20
lines changed

4 files changed

+6
-20
lines changed

lambda-http/src/lib.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
//! your function's execution path.
1818
//!
1919
//! ```rust,no_run
20-
//! use lambda_http::{handler, lambda_runtime};
21-
//!
22-
//! type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
20+
//! use lambda_http::{handler, lambda_runtime::{self, Error}};
2321
//!
2422
//! #[tokio::main]
2523
//! async fn main() -> Result<(), Error> {
@@ -36,9 +34,7 @@
3634
//! with the [`RequestExt`](trait.RequestExt.html) trait.
3735
//!
3836
//! ```rust,no_run
39-
//! use lambda_http::{handler, lambda_runtime::{self, Context}, IntoResponse, Request, RequestExt};
40-
//!
41-
//! type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
37+
//! use lambda_http::{handler, lambda_runtime::{self, Context, Error}, IntoResponse, Request, RequestExt};
4238
//!
4339
//! #[tokio::main]
4440
//! async fn main() -> Result<(), Error> {
@@ -66,8 +62,8 @@
6662
extern crate maplit;
6763

6864
pub use http::{self, Response};
69-
use lambda_runtime::Handler as LambdaHandler;
7065
pub use lambda_runtime::{self, Context};
66+
use lambda_runtime::{Error, Handler as LambdaHandler};
7167

7268
mod body;
7369
pub mod ext;
@@ -85,9 +81,6 @@ use std::{
8581
task::{Context as TaskContext, Poll},
8682
};
8783

88-
/// Error type that lambdas may result in
89-
pub(crate) type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
90-
9184
/// Type alias for `http::Request`s with a fixed [`Body`](enum.Body.html) type
9285
pub type Request = http::Request<Body>;
9386

lambda-runtime/examples/basic.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
// This example requires the following input to succeed:
22
// { "command": "do something" }
33

4-
use lambda_runtime::{handler_fn, Context};
4+
use lambda_runtime::{handler_fn, Context, Error};
55
use log::LevelFilter;
66
use serde::{Deserialize, Serialize};
77
use simple_logger::SimpleLogger;
88

9-
/// A shorthand for `Box<dyn std::error::Error + Send + Sync + 'static>`
10-
/// type required by aws-lambda-rust-runtime.
11-
pub type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
12-
139
/// This is also a made-up example. Requests come into the runtime as unicode
1410
/// strings in json format, which can map to any structure that implements `serde::Deserialize`
1511
/// The runtime pays no attention to the contents of the request payload.

lambda-runtime/examples/error-handling.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
/// See https://github.com/awslabs/aws-lambda-rust-runtime for more info on Rust runtime for AWS Lambda
2-
use lambda_runtime::handler_fn;
2+
use lambda_runtime::{handler_fn, Error};
33
use log::LevelFilter;
44
use serde::{Deserialize, Serialize};
55
use serde_json::{json, Value};
66
use simple_logger::SimpleLogger;
77
use std::fs::File;
88

9-
/// A shorthand for `Box<dyn std::error::Error + Send + Sync + 'static>` type required by aws-lambda-rust-runtime.
10-
pub type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
11-
129
/// A simple Lambda request structure with just one field
1310
/// that tells the Lambda what is expected of it.
1411
#[derive(Deserialize)]

lambda-runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use requests::{EventCompletionRequest, EventErrorRequest, IntoRequest, NextEvent
3131
use types::Diagnostic;
3232

3333
/// Error type that lambdas may result in
34-
pub(crate) type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
34+
pub type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
3535

3636
/// Configuration derived from environment variables.
3737
#[derive(Debug, Default, Clone, PartialEq)]

0 commit comments

Comments
 (0)