Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

One-shot — OwnedPipeline

#![allow(unused)]
fn main() {
/// One-shot pipeline over the `Owned` domain. Not `Clone`; runs
/// via [`crate::source::PipelineExecOnce::run_from_node_once`],
/// which consumes `self`.
#[must_use]
pub struct OwnedPipeline<N, H, R>
where N: 'static, H: 'static, R: 'static,
{
    pub(crate) treeish: Edgy<N, N>,
    pub(crate) fold:    Fold<N, H, R>,
}
}

Two slots, like TreeishPipeline, but stored in the Owned domain — closures are Box<dyn Fn>, not Clone, not Send + Sync. Runs once and is consumed.

Constructor

#![allow(unused)]
fn main() {
let pipeline = OwnedPipeline::new(
    treeish,    // owned::Edgy<N, N>
    fold,       // owned::Fold<N, H, R>
);
}

Running

#![allow(unused)]
fn main() {
let r = pipeline.run_from_node_once(&FUSED, &root);
// pipeline is consumed.
}

run_from_node_once is the by-value method on PipelineExecOnce, the consuming counterpart of PipelineExec::run_from_node. Owned does not implement ShapeCapable, so Stage-2 sugars are not available — there is no chain to compose.

Worked example

#![allow(unused)]
fn main() {
    #[test]
    fn owned_pipeline_example() {
        use hylic_pipeline::{OwnedPipeline, PipelineExecOnce};
        use hylic::domain::owned as odom;

        let graph = odom::edgy::treeish(|n: &u64|
            if *n > 0 { vec![*n - 1] } else { vec![] });
        let fld = odom::fold(
            |n: &u64| *n,
            |h: &mut u64, c: &u64| *h += c,
            |h: &u64| *h,
        );

        let r: u64 = OwnedPipeline::new(graph, fld)
            .run_from_node_once(&odom::FUSED, &5u64);
        // 5+4+3+2+1+0 = 15.
        assert_eq!(r, 15);
    }
}