1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//! 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}!")))
//! }
//! }
//!
//! # fn block_on<F: std::future::Future>(fut: F) -> F::Output {
//! # use std::task::{Context as TaskContext, Poll, Waker};
//! # let mut fut = std::pin::pin!(fut);
//! # let mut cx = TaskContext::from_waker(Waker::noop());
//! # loop {
//! # if let Poll::Ready(val) = fut.as_mut().poll(&mut cx) {
//! # return val;
//! # }
//! # }
//! # }
//! #
//! let pipeline = Pipeline::<(), String>::builder()
//! .step(LoadName)
//! .step(Greet)
//! .build()?;
//!
//! let greeting = block_on(pipeline.run(()))?;
//! assert_eq!(greeting, "Hello, Ada!");
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;