rtlambda/
lib.rs

1// Copyright 2022 Guy Or and the "rtlambda" authors. All rights reserved.
2
3// `SPDX-License-Identifier: MIT OR Apache-2.0`
4
5/// Implementations of the `rtlambda` API for different HTTP backends.
6pub mod backends;
7/// A collection of traits and default implementations for them, representing the library's core data structures.
8pub mod data;
9/// Defines error types and constants.
10pub mod error;
11/// Defines the [`crate::runtime::LambdaRuntime`] API and provides a default generic implementation.
12pub mod runtime;
13/// Defines the [`crate::transport::Transport`] abstraction used to support multiple HTTP backends.
14pub mod transport;
15
16/// The current Lambda API version used on AWS.
17pub static LAMBDA_VER: &str = "2018-06-01";
18
19/// A prelude that contains all the relevant imports when using the library's default runtime implementation,
20/// which currently ships with a [ureq](https://crates.io/crates/ureq) based HTTP Backend and [serde_json](https://crates.io/crates/serde_json) for serialization.
21pub mod prelude {
22    pub use crate::backends::ureq::*;
23    pub use crate::data::context::{LambdaContext, RefLambdaContext};
24    pub use crate::data::env::LambdaRuntimeEnv;
25    pub use crate::runtime::{DefaultRuntime, LambdaRuntime};
26    pub use crate::LAMBDA_VER;
27}
28
29/// Creates a [`crate::runtime::DefaultRuntime`] with the given response, transport, env, out, err types as well as version and initializer.
30#[macro_export]
31macro_rules! create_runtime {
32    ($response:ty, $transport:ty, $env:ty, $out:ty, $err:ty, $ver:expr, $init:ident) => {
33        DefaultRuntime::<$response, $transport, $env, $out, $err>::new($ver, $init);
34    };
35}
36
37/// Creates a [`crate::runtime::DefaultRuntime`] with ureq based HTTP backend and the default implementation of env-vars handling.
38#[macro_export]
39macro_rules! default_runtime {
40    ($out:ty, $err:ty, $ver:expr, $init:ident) => {
41        create_runtime!(
42            UreqResponse,
43            UreqTransport,
44            LambdaRuntimeEnv,
45            $out,
46            $err,
47            $ver,
48            $init
49        )
50    };
51}