Skip to main content

DagChain

Struct DagChain 

Source
pub struct DagChain<E, Out, Chain> { /* private fields */ }
Expand description

Main chain builder for a typed DAG.

Chain implements [ChainCall<E, Out = Out>] — a named node type representing all steps composed so far. No closures, no use<>.

Implementations§

Source§

impl<E, Out: 'static, Chain> DagChain<E, Out, Chain>

Source

pub fn fork(self) -> DagChainFork<E, Out, Chain, ()>

Enter fork mode. Subsequent .arm() calls add parallel branches.

Source§

impl<E, Chain> DagChain<E, (), Chain>
where Chain: ChainCall<E, Out = ()> + Send,

Source

pub fn build(self) -> Dag<Chain>

Finalize into a Dag that implements Handler<E>.

Only available when the chain ends with () or Option<()>. If your DAG produces a value, add a final .then() that consumes the output.

Source§

impl<E, Chain> DagChain<E, Option<()>, Chain>
where Chain: ChainCall<E, Out = Option<()>> + Send,

Source

pub fn build(self) -> Dag<DiscardOptionNode<Chain>>

Finalize into a Dag, discarding the Option<()>.

DAGs ending with Option<()> produce the same Dag as those ending with ().

Source§

impl<E, Out: 'static, Chain> DagChain<E, Out, Chain>

Source

pub fn then<NewOut, Params, S>( self, f: S, registry: &Registry, ) -> DagChain<E, NewOut, DagThenNode<Chain, S::Step, NewOut>>
where NewOut: 'static, S: IntoStep<&'static Out, NewOut, Params>, S::Step: for<'a> StepCall<&'a Out, Out = NewOut>,

Append a step. The step receives &Out by reference.

Source

pub fn dispatch<H: Handler<Out>>( self, handler: H, ) -> DagChain<E, (), DispatchNode<Chain, H>>

Dispatch output to a Handler<Out>.

Source

pub fn guard<Params, S: IntoRefStep<Out, bool, Params>>( self, f: S, registry: &Registry, ) -> DagChain<E, Option<Out>, GuardNode<Chain, S::Step>>

Conditionally wrap the output in Option.

Source

pub fn view<V: View<Out>>(self) -> ViewScope<E, Out, V, Chain, ()>

Open a view scope. Steps inside operate on a read-only view constructed from the event. Close with .end_view().

Source

pub fn tap<Params, S: IntoRefStep<Out, (), Params>>( self, f: S, registry: &Registry, ) -> DagChain<E, Out, TapNode<Chain, S::Step>>

Observe the current value without consuming or changing it.

Source

pub fn route<NewOut, C0, C1, Params, Pred: IntoRefStep<Out, bool, Params>>( self, pred: Pred, registry: &Registry, on_true: DagArm<Out, NewOut, C0>, on_false: DagArm<Out, NewOut, C1>, ) -> DagChain<E, NewOut, DagRouteNode<Chain, Pred::Step, C0, C1, NewOut>>
where C0: for<'a> ChainCall<&'a Out, Out = NewOut>, C1: for<'a> ChainCall<&'a Out, Out = NewOut>,

Binary conditional routing. Both arms borrow &Out.

Source

pub fn tee<C>( self, side: DagArm<Out, (), C>, ) -> DagChain<E, Out, TeeNode<Chain, C>>
where C: for<'a> ChainCall<&'a Out, Out = ()>,

Fork off a multi-step side-effect chain.

Source

pub fn scan<Acc, NewOut, Params, S>( self, initial: Acc, f: S, registry: &Registry, ) -> DagChain<E, NewOut, RefScanNode<Chain, S::Step, Acc>>
where Acc: 'static, NewOut: 'static, S: IntoRefScanStep<Acc, Out, NewOut, Params>,

Scan with persistent accumulator. The step receives &mut Acc and &Out by reference.

Source§

impl<E, Out: PartialEq + Clone + 'static, Chain> DagChain<E, Out, Chain>

Source

pub fn dedup(self) -> DagChain<E, Option<Out>, DedupNode<Chain, Out>>

Suppress consecutive unchanged values.

Source§

impl<E, Chain> DagChain<E, bool, Chain>

Source

pub fn not(self) -> DagChain<E, bool, NotNode<Chain>>

Invert a boolean value.

Source

pub fn and<Params, S: IntoProducer<bool, Params>>( self, f: S, registry: &Registry, ) -> DagChain<E, bool, AndBoolNode<Chain, S::Step>>

Short-circuit AND with a second boolean.

Source

pub fn or<Params, S: IntoProducer<bool, Params>>( self, f: S, registry: &Registry, ) -> DagChain<E, bool, OrBoolNode<Chain, S::Step>>

Short-circuit OR with a second boolean.

Source

pub fn xor<Params, S: IntoProducer<bool, Params>>( self, f: S, registry: &Registry, ) -> DagChain<E, bool, XorBoolNode<Chain, S::Step>>

XOR with a second boolean.

Source§

impl<'a, E, T: Clone, Chain> DagChain<E, &'a T, Chain>

Source

pub fn cloned(self) -> DagChain<E, T, ClonedNode<Chain>>

Clone a borrowed output to produce an owned value.

Source§

impl<'a, E, T: Clone, Chain> DagChain<E, Option<&'a T>, Chain>

Source

pub fn cloned(self) -> DagChain<E, Option<T>, ClonedOptionNode<Chain>>

Clone inner borrowed value. Option<&T>Option<T>.

Source§

impl<'a, E, T: Clone, Err, Chain> DagChain<E, Result<&'a T, Err>, Chain>

Source

pub fn cloned(self) -> DagChain<E, Result<T, Err>, ClonedResultNode<Chain>>

Clone inner borrowed Ok value.

Source§

impl<E, T: 'static, Chain> DagChain<E, Option<T>, Chain>

Source

pub fn map<U, Params, S: IntoStep<&'static T, U, Params>>( self, f: S, registry: &Registry, ) -> DagChain<E, Option<U>, DagMapOptionNode<Chain, S::Step, U>>
where U: 'static, S::Step: for<'x> StepCall<&'x T, Out = U>,

Transform the inner value. Step not called on None.

Source

pub fn and_then<U, Params, S: IntoStep<&'static T, Option<U>, Params>>( self, f: S, registry: &Registry, ) -> DagChain<E, Option<U>, DagAndThenOptionNode<Chain, S::Step, U>>
where U: 'static, S::Step: for<'x> StepCall<&'x T, Out = Option<U>>,

Short-circuits on None. std: Option::and_then

Source

pub fn on_none<Params, S: IntoProducer<(), Params>>( self, f: S, registry: &Registry, ) -> DagChain<E, Option<T>, OnNoneNode<Chain, S::Step>>

Side effect on None.

Source

pub fn filter<Params, S: IntoRefStep<T, bool, Params>>( self, f: S, registry: &Registry, ) -> DagChain<E, Option<T>, FilterNode<Chain, S::Step>>

Keep value if predicate holds. std: Option::filter

Source

pub fn inspect<Params, S: IntoRefStep<T, (), Params>>( self, f: S, registry: &Registry, ) -> DagChain<E, Option<T>, InspectOptionNode<Chain, S::Step>>

Side effect on Some value. std: Option::inspect

Source

pub fn ok_or<Err: Clone>( self, err: Err, ) -> DagChain<E, Result<T, Err>, OkOrNode<Chain, Err>>

None becomes Err(err). std: Option::ok_or

Source

pub fn ok_or_else<Err, Params, S: IntoProducer<Err, Params>>( self, f: S, registry: &Registry, ) -> DagChain<E, Result<T, Err>, OkOrElseNode<Chain, S::Step>>

None becomes Err(f()). std: Option::ok_or_else

Source

pub fn unwrap_or( self, default: T, ) -> DagChain<E, T, UnwrapOrOptionNode<Chain, T>>
where T: Clone,

Exit Option — None becomes the default value.

Source

pub fn unwrap_or_else<Params, S: IntoProducer<T, Params>>( self, f: S, registry: &Registry, ) -> DagChain<E, T, UnwrapOrElseOptionNode<Chain, S::Step>>

Exit Option — None becomes f().

Source§

impl<E, T: 'static, Err: 'static, Chain> DagChain<E, Result<T, Err>, Chain>

Source

pub fn map<U, Params, S: IntoStep<&'static T, U, Params>>( self, f: S, registry: &Registry, ) -> DagChain<E, Result<U, Err>, DagMapResultNode<Chain, S::Step, U>>
where U: 'static, S::Step: for<'x> StepCall<&'x T, Out = U>,

Transform the Ok value. Step not called on Err.

Source

pub fn and_then<U, Params, S: IntoStep<&'static T, Result<U, Err>, Params>>( self, f: S, registry: &Registry, ) -> DagChain<E, Result<U, Err>, DagAndThenResultNode<Chain, S::Step, U>>
where U: 'static, S::Step: for<'x> StepCall<&'x T, Out = Result<U, Err>>,

Short-circuits on Err. std: Result::and_then

Source

pub fn catch<Params, S: IntoStep<&'static Err, (), Params>>( self, f: S, registry: &Registry, ) -> DagChain<E, Option<T>, DagCatchNode<Chain, S::Step>>
where S::Step: for<'x> StepCall<&'x Err, Out = ()>,

Handle error and transition to Option.

Source

pub fn map_err<Err2, Params, S: IntoStep<Err, Err2, Params>>( self, f: S, registry: &Registry, ) -> DagChain<E, Result<T, Err2>, MapErrNode<Chain, S::Step>>

Transform the error. std: Result::map_err

Source

pub fn or_else<Err2, Params, S: IntoStep<Err, Result<T, Err2>, Params>>( self, f: S, registry: &Registry, ) -> DagChain<E, Result<T, Err2>, OrElseNode<Chain, S::Step>>

Recover from Err. std: Result::or_else

Source

pub fn inspect<Params, S: IntoRefStep<T, (), Params>>( self, f: S, registry: &Registry, ) -> DagChain<E, Result<T, Err>, InspectResultNode<Chain, S::Step>>

Side effect on Ok. std: Result::inspect

Source

pub fn inspect_err<Params, S: IntoRefStep<Err, (), Params>>( self, f: S, registry: &Registry, ) -> DagChain<E, Result<T, Err>, InspectErrNode<Chain, S::Step>>

Side effect on Err. std: Result::inspect_err

Source

pub fn ok(self) -> DagChain<E, Option<T>, OkResultNode<Chain>>

Discard error, enter Option land. std: Result::ok

Source

pub fn unwrap_or( self, default: T, ) -> DagChain<E, T, UnwrapOrResultNode<Chain, T>>
where T: Clone,

Exit Result — Err becomes the default value.

Source

pub fn unwrap_or_else<Params, S: IntoStep<Err, T, Params>>( self, f: S, registry: &Registry, ) -> DagChain<E, T, UnwrapOrElseResultNode<Chain, S::Step>>

Exit Result — Err becomes f(err).

Source§

impl<E, T0: 'static, T1: 'static, Chain> DagChain<E, (T0, T1), Chain>

Source

pub fn splat(self) -> DagSplatChain2<E, T0, T1, Chain>

Destructure the tuple output into individual &T arguments.

Source§

impl<E, T0: 'static, T1: 'static, T2: 'static, Chain> DagChain<E, (T0, T1, T2), Chain>

Source

pub fn splat(self) -> DagSplatChain3<E, T0, T1, T2, Chain>

Destructure the tuple output into individual &T arguments.

Source§

impl<E, T0: 'static, T1: 'static, T2: 'static, T3: 'static, Chain> DagChain<E, (T0, T1, T2, T3), Chain>

Source

pub fn splat(self) -> DagSplatChain4<E, T0, T1, T2, T3, Chain>

Destructure the tuple output into individual &T arguments.

Source§

impl<E, T0: 'static, T1: 'static, T2: 'static, T3: 'static, T4: 'static, Chain> DagChain<E, (T0, T1, T2, T3, T4), Chain>

Source

pub fn splat(self) -> DagSplatChain5<E, T0, T1, T2, T3, T4, Chain>

Destructure the tuple output into individual &T arguments.

Source§

impl<E, Out: PipelineOutput, Chain: ChainCall<E, Out = Out>> DagChain<E, Out, Chain>

Source

pub fn build_batch(self, capacity: usize) -> BatchDag<E, Chain>

Finalize into a BatchDag with a pre-allocated input buffer.

Same DAG chain as build, but the DAG owns an input buffer that drivers fill between dispatch cycles. Each call to BatchDag::run drains the buffer, running every item through the chain independently.

Available when the DAG ends with () or Option<()> (e.g. after .guard() or .filter() followed by .unwrap_or(())).

capacity is the initial allocation — the buffer can grow if needed, but sizing it for the expected batch size avoids reallocation.

Auto Trait Implementations§

§

impl<E, Out, Chain> Freeze for DagChain<E, Out, Chain>
where Chain: Freeze,

§

impl<E, Out, Chain> RefUnwindSafe for DagChain<E, Out, Chain>
where Chain: RefUnwindSafe,

§

impl<E, Out, Chain> Send for DagChain<E, Out, Chain>
where Chain: Send,

§

impl<E, Out, Chain> Sync for DagChain<E, Out, Chain>
where Chain: Sync,

§

impl<E, Out, Chain> Unpin for DagChain<E, Out, Chain>
where Chain: Unpin,

§

impl<E, Out, Chain> UnsafeUnpin for DagChain<E, Out, Chain>
where Chain: UnsafeUnpin,

§

impl<E, Out, Chain> UnwindSafe for DagChain<E, Out, Chain>
where Chain: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.