use crossbeam_channel::Sender; use std::sync::Arc; use super::error::PipelineError; // ── Function types ──────────────────────────────────────────────────────────── /// Source function: called repeatedly, returns the next item or `EndOfStream`. /// `FnMut` because it keeps an internal state (position in the iterator). pub type SourceFn = Box Result + Send>; /// Sink function: consumes a final item, may fail (I/O error, etc.). pub type SinkFn = Box Result<(), PipelineError> + Send>; /// Transform function shared between workers through an `Arc`. pub type SharedFn = Arc Result + Send + Sync>; /// 1→N transform function (flat map) shared between workers through an `Arc`. /// /// The function receives the input item, a `push` channel to send each produced /// item, and a `delta` channel to tell the scheduler how many additional items /// entered the pipeline (N-1 if N items are produced). /// It must call `delta.send(N - 1)` **after** pushing all the items. pub type SharedFlatFn = Arc>, &Sender) + Send + Sync>; // ── Stage enum ──────────────────────────────────────────────────────────────── /// A pipeline stage: plain transform (1→1) or flat transform (1→N). pub enum Stage { /// 1→1 transform. Transform(SharedFn), /// 1→N flat transform. Flat(SharedFlatFn), } impl Clone for Stage { fn clone(&self) -> Self { match self { Stage::Transform(f) => Stage::Transform(Arc::clone(f)), Stage::Flat(f) => Stage::Flat(Arc::clone(f)), } } } // ── Worker task ─────────────────────────────────────────────────────────────── pub(super) enum WorkerTask { Transform(D, usize), Flat(D, usize), }