rskit_chain/lib.rs
1//! Typed sequential chain execution for rskit.
2//!
3//! A chain is a statically typed sequence where each step receives the previous step's output
4//! and returns the next step's input type.
5//! Execution short-circuits on the first [`AppError`](rskit_errors::AppError),
6//! checks cancellation between steps,
7//! and runs registered cleanup actions for already-completed steps when a later failure
8//! or cancellation interrupts the chain.
9//!
10//! # Quick start
11//!
12//! ```
13//! use rskit_chain::{ChainBuilder, Step};
14//! use tokio_util::sync::CancellationToken;
15//!
16//! # async fn run() -> rskit_errors::AppResult<()> {
17//! let chain = ChainBuilder::new()
18//! .step(Step::from_fn("parse", |input: String, _ctx| async move {
19//! input.parse::<u32>().map_err(|err| {
20//! rskit_errors::AppError::invalid_input("input", err.to_string())
21//! })
22//! }))
23//! .step(Step::from_fn("double", |value: u32, _ctx| async move {
24//! Ok(value * 2)
25//! }))
26//! .build();
27//!
28//! let output = chain
29//! .execute("21".to_string(), None, CancellationToken::new())
30//! .await?;
31//! assert_eq!(output, 42);
32//! # Ok(())
33//! # }
34//! ```
35
36#![warn(missing_docs)]
37
38/// Fluent builder for constructing typed chain executors.
39pub mod builder;
40/// Typed sequential chain executor.
41pub mod executor;
42/// Typed step primitives.
43pub mod operation;
44/// Progress types.
45pub mod types;
46
47pub use builder::ChainBuilder;
48pub use executor::{Chain, ChainProgressFn};
49pub use operation::{Step, StepContext, StepFuture};
50pub use types::{StepProgress, StepStatus};
51
52#[cfg(test)]
53mod tests;