File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 2525//! ))
2626//! }
2727//! ```
28+ //!
29+ //! You can also provide a closure directly to the `lambda!` macro
30+ //!
31+ //! ```rust,no_run
32+ //! use lambda_http::{lambda, Request, RequestExt};
33+ //!
34+ //! fn main() {
35+ //! lambda!(
36+ //! |request: Request, context| Ok(
37+ //! format!(
38+ //! "hello {}",
39+ //! request.query_string_parameters()
40+ //! .get("name")
41+ //! .unwrap_or_else(|| "stranger")
42+ //! )
43+ //! )
44+ //! )
45+ //! }
46+ //! ```
2847
2948pub use http:: { self , Response } ;
3049use lambda_runtime:: { self as lambda, error:: HandlerError , Context } ;
@@ -87,6 +106,12 @@ where
87106/// A macro for starting new handler's poll for API Gateway events
88107#[ macro_export]
89108macro_rules! lambda {
109+ ( $handler: expr) => {
110+ $crate:: start( $handler, None )
111+ } ;
112+ ( $handler: expr, $runtime: expr) => {
113+ $crate:: start( $handler, Some ( $runtime) )
114+ } ;
90115 ( $handler: ident) => {
91116 $crate:: start( $handler, None )
92117 } ;
Original file line number Diff line number Diff line change 3939//! })
4040//! }
4141//! ```
42+ //!
43+ //! You can also provide a closure directly to the `lambda!` macro
44+ //!
45+ //! ```rust,no_run
46+ //! #[macro_use]
47+ //! extern crate serde_derive;
48+ //! #[macro_use]
49+ //! extern crate lambda_runtime;
50+ //!
51+ //! use lambda_runtime::{Context, error::HandlerError};
52+ //!
53+ //!
54+ //! #[derive(Deserialize, Clone)]
55+ //! struct CustomEvent {
56+ //! first_name: String,
57+ //! last_name: String,
58+ //! }
59+ //!
60+ //! #[derive(Serialize, Clone)]
61+ //! struct CustomOutput {
62+ //! message: String,
63+ //! }
64+ //!
65+ //! fn main() {
66+ //! lambda!(
67+ //! |e: CustomEvent, ctx: Context| {
68+ //! if e.first_name == "" {
69+ //! return Err(ctx.new_error("Missing first name!"));
70+ //! }
71+ //! Ok(CustomOutput{
72+ //! message: format!("Hello, {}!", e.first_name),
73+ //! })
74+ //! }
75+ //! );
76+ //! }
77+ //! ```
4278#[ macro_use]
4379extern crate log;
4480
Original file line number Diff line number Diff line change @@ -50,6 +50,12 @@ macro_rules! lambda {
5050 ( $handler: ident, $runtime: expr) => {
5151 $crate:: start( $handler, Some ( $runtime) )
5252 } ;
53+ ( $handler: expr) => {
54+ $crate:: start( $handler, None )
55+ } ;
56+ ( $handler: expr, $runtime: expr) => {
57+ $crate:: start( $handler, Some ( $runtime) )
58+ } ;
5359}
5460
5561/// Internal implementation of the start method that receives a config provider. This method
You can’t perform that action at this time.
0 commit comments