File tree 3 files changed +67
-0
lines changed
3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 25
25
//! ))
26
26
//! }
27
27
//! ```
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
+ //! ```
28
47
29
48
pub use http:: { self , Response } ;
30
49
use lambda_runtime:: { self as lambda, error:: HandlerError , Context } ;
@@ -87,6 +106,12 @@ where
87
106
/// A macro for starting new handler's poll for API Gateway events
88
107
#[ macro_export]
89
108
macro_rules! lambda {
109
+ ( $handler: expr) => {
110
+ $crate:: start( $handler, None )
111
+ } ;
112
+ ( $handler: expr, $runtime: expr) => {
113
+ $crate:: start( $handler, Some ( $runtime) )
114
+ } ;
90
115
( $handler: ident) => {
91
116
$crate:: start( $handler, None )
92
117
} ;
Original file line number Diff line number Diff line change 39
39
//! })
40
40
//! }
41
41
//! ```
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
+ //! ```
42
78
#[ macro_use]
43
79
extern crate log;
44
80
Original file line number Diff line number Diff line change @@ -50,6 +50,12 @@ macro_rules! lambda {
50
50
( $handler: ident, $runtime: expr) => {
51
51
$crate:: start( $handler, Some ( $runtime) )
52
52
} ;
53
+ ( $handler: expr) => {
54
+ $crate:: start( $handler, None )
55
+ } ;
56
+ ( $handler: expr, $runtime: expr) => {
57
+ $crate:: start( $handler, Some ( $runtime) )
58
+ } ;
53
59
}
54
60
55
61
/// 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