pipe_io/lib.rs
1//! Typed source-transform-sink pipelines with backpressure, batching, and
2//! per-stage error isolation. A lightweight runtime-agnostic stream processor
3//! for in-process workloads. The missing middle ground between raw iterators
4//! and full distributed stream processing.
5//!
6//! # Quick start
7//!
8//! ```
9//! use pipe_io::{Pipeline, sink::VecSink};
10//!
11//! let sink = VecSink::<i64>::new();
12//! let handle = sink.handle();
13//!
14//! Pipeline::from_iter(1..=5)
15//! .map(|n: i32| i64::from(n) * 10)
16//! .filter(|n: &i64| *n > 20)
17//! .sink(sink)
18//! .run()
19//! .expect("pipeline run");
20//!
21//! assert_eq!(handle.take(), vec![30, 40, 50]);
22//! ```
23//!
24//! # Features
25//!
26//! * `std` (default): enables [`source::ChannelSource`],
27//! [`source::ReaderSource`], [`sink::ChannelSink`],
28//! [`sink::WriterSink`], and [`driver::ThreadedDriver`]. With `std`
29//! disabled the crate compiles in `no_std` mode (requires `alloc`)
30//! with the data primitives, closure-based adapters, batching, and
31//! [`driver::SyncDriver`] available.
32//!
33//! # Design notes
34//!
35//! Sources are pull-based (`Source::pull`). Stages receive items one at
36//! a time and emit zero or more outputs via an [`Emit`] callback handed
37//! in by the driver. Sinks are push-based (`Sink::write`). The
38//! builder is fully typed; the carrier type of the pipeline is tracked
39//! at compile time across every stage transition. See `REPS.md` for the
40//! binding API contract and `.dev/DESIGN.md` for design notes.
41
42#![doc(html_root_url = "https://docs.rs/pipe-io")]
43#![cfg_attr(docsrs, feature(doc_cfg))]
44#![cfg_attr(not(feature = "std"), no_std)]
45#![forbid(unsafe_code)]
46#![warn(missing_docs)]
47#![warn(clippy::all)]
48
49extern crate alloc;
50
51/// Crate version string, populated by Cargo at build time.
52pub const VERSION: &str = env!("CARGO_PKG_VERSION");
53
54pub mod batch;
55pub mod driver;
56pub mod emit;
57pub mod error;
58pub mod sink;
59pub mod source;
60pub mod stage;
61#[cfg(feature = "std")]
62pub mod window;
63
64mod pipeline;
65mod stage_id;
66
67pub use crate::batch::{Batch, BatchPolicy, ByteSize};
68pub use crate::driver::{Driver, RunStats};
69pub use crate::emit::{Emit, EmitError};
70pub use crate::error::{BoxError, Error, ErrorPolicy, Result, StageError, StageFailure};
71pub use crate::pipeline::{Pipeline, PipelineBuilder};
72pub use crate::sink::Sink;
73pub use crate::source::Source;
74pub use crate::stage::Stage;
75pub use crate::stage_id::StageId;
76#[cfg(feature = "std")]
77pub use crate::window::{Clock, SystemClock, Window, WindowPolicy};