Skip to main content

atomr_streams/
graph.rs

1//! GraphDsl — minimal builder for fan-in / fan-out stream graphs.
2//!
3//! Linear composition lives on `Source::via`; this module collects the
4//! fan-in / fan-out junctions so callers can assemble a linear-plus-junction
5//! graph without needing the full upstream graph-DSL runtime.
6
7use crate::flow::Flow;
8use crate::sink::Sink;
9use crate::source::Source;
10
11pub struct GraphDsl;
12
13impl GraphDsl {
14    pub fn linear<A, B>(source: Source<A>, flow: Flow<A, B>) -> Source<B>
15    where
16        A: Send + 'static,
17        B: Send + 'static,
18    {
19        source.via(flow)
20    }
21
22    pub async fn run_fold<A, Acc, F>(source: Source<A>, init: Acc, f: F) -> Acc
23    where
24        A: Send + 'static,
25        Acc: Send + 'static,
26        F: FnMut(Acc, A) -> Acc + Send + 'static,
27    {
28        Sink::fold(source, init, f).await
29    }
30}