Expand description
A small toolkit for building linear, async processing pipelines out of
independently testable steps that communicate through a shared,
type-keyed Context.
Each Step declares, via Step::access, exactly which types it
reads, writes, or consumes from the Context. PipelineBuilder::build
uses those declarations to catch wiring mistakes — a step reading a type
nothing upstream produces — before the pipeline ever runs, and
Context enforces them again at run time, so a step that reads or
writes something it didn’t declare fails fast with
PipelineError::AccessViolation instead of silently drifting from its
declared contract.
§Examples
use pipeline_toolkit::{AccessSpec, Context, Flow, Pipeline, Step, StepError};
struct LoadName;
#[async_trait::async_trait]
impl Step<String> for LoadName {
fn name(&self) -> &str {
"load_name"
}
fn access(&self) -> AccessSpec {
AccessSpec::new().writes::<String>()
}
async fn run(&self, ctx: &mut Context) -> Result<Flow<String>, StepError> {
ctx.insert("Ada".to_string());
Ok(Flow::Continue)
}
}
struct Greet;
#[async_trait::async_trait]
impl Step<String> for Greet {
fn name(&self) -> &str {
"greet"
}
fn access(&self) -> AccessSpec {
AccessSpec::new().reads::<String>()
}
async fn run(&self, ctx: &mut Context) -> Result<Flow<String>, StepError> {
let name = ctx.get::<String>().expect("declared as read").clone();
Ok(Flow::Done(format!("Hello, {name}!")))
}
}
let pipeline = Pipeline::<(), String>::builder()
.step(LoadName)
.step(Greet)
.build()?;
let greeting = block_on(pipeline.run(()))?;
assert_eq!(greeting, "Hello, Ada!");Structs§
- Access
Spec - The set of
Contextentry types aStepis allowed to read, write, or consume, keyed byTypeId. - Access
Violation - Records an undeclared
Contextaccess: a step read, wrote, or consumed a type itsAccessSpecdidn’t grant. - Arm
- A named sequence of
Steps that runs as one option of aBranch. - ArmBuilder
- Incrementally assembles an
Arm, returned byArm::builder. - Branch
- A framework-provided
Stepthat runs one of several named arms, chosen at run time by a key-selecting condition function. - Branch
Builder - Incrementally assembles a
Branch, returned byBranch::builder. - Context
- A type-keyed store of at most one value per type, shared across the
steps of a running
Pipeline. - Loop
- A framework-provided
Stepthat runs the sameArmbody repeatedly, do-while style, until a condition function says to stop ormax_iterationsis reached. - Loop
Builder - Incrementally assembles a
Loop, returned byLoop::builder. - Pipeline
- A validated, immutable sequence of
Steps, built viaSelf::builder. - Pipeline
Builder - Incrementally assembles a
Pipeline, returned byPipeline::builder. - Step
Error - The error type returned by
Step::run.
Enums§
- Access
Kind - The kind of
Contextaccess aStepperformed, used to describe anAccessViolation. - Build
Error - Why
PipelineBuilder::buildrejected a pipeline. - Flow
- What a
Stepwants thePipelineto do next. - Pipeline
Error - Why
Pipeline::runfailed.