Skip to main content

durable_lambda_trait/
lib.rs

1//! Trait-based API approach for durable Lambda handlers.
2//!
3//! This crate provides a trait-based API for writing durable Lambda functions
4//! with a structured, object-oriented approach. Implement [`DurableHandler`] on
5//! your struct, then use [`run`] as the single entry point — it handles all
6//! `lambda_runtime` and `DurableContext` wiring internally.
7//!
8//! # Quick Start
9//!
10//! ```no_run
11//! use durable_lambda_trait::prelude::*;
12//! use async_trait::async_trait;
13//!
14//! struct OrderProcessor;
15//!
16//! #[async_trait]
17//! impl DurableHandler for OrderProcessor {
18//!     async fn handle(
19//!         &self,
20//!         event: serde_json::Value,
21//!         mut ctx: TraitContext,
22//!     ) -> Result<serde_json::Value, DurableError> {
23//!         let order = ctx.step("validate_order", || async {
24//!             Ok::<_, String>(serde_json::json!({"id": 123, "valid": true}))
25//!         }).await?;
26//!         Ok(serde_json::json!({"order": order}))
27//!     }
28//! }
29//!
30//! #[tokio::main]
31//! async fn main() -> Result<(), lambda_runtime::Error> {
32//!     durable_lambda_trait::run(OrderProcessor).await
33//! }
34//! ```
35
36pub mod context;
37pub mod handler;
38pub mod prelude;
39
40pub use context::TraitContext;
41pub use handler::{run, DurableHandler};