Builder

Struct Builder 

Source
pub struct Builder<Input, Output, Error, Context, NodeTypes = (), NodeIOETypes = ()>
where Input: Send + Clone, Error: Send, Context: Fork + Join + Send,
{ /* private fields */ }
Expand description

Builder for ParallelFlow.

This builder ensures:

  • Input into the flow can be converted into the input of all nodes
  • error of all nodes can be converted into the Error of the flow
  • Joiner returns Result<Output, Error>

See also ParallelFlow.

Implementations§

Source§

impl<Input, Output, Error, Context> Builder<Input, Output, Error, Context>
where Input: Send + Clone, Error: Send, Context: Fork + Join + Send,

Source

pub fn new() -> Self

Creates a new empty builder for ParallelFlow.

Source

pub fn add_node<NodeType, NodeInput, NodeOutput, NodeError>( self, node: NodeType, ) -> Builder<Input, Output, Error, Context, (NodeType,), ((), (NodeInput, NodeOutput<NodeOutput>, NodeError))>
where Input: Into<NodeInput>, NodeError: Into<Error>, NodeType: Node<NodeInput, NodeOutputStruct<NodeOutput>, NodeError, Context> + Send + Sync + Clone, NodeOutput: Send,

Adds a new node.

The new node must satisfy:

  • Self: Node<NodeInputType, NodeOutput<NodeOutputType>, NodeErrorType, _>
  • Input: Into<NodeInputType>,
  • NodeErrorType: Into<Error>,
§Returns

A new Builder with the added node.

Source§

impl<Input, Output, Error, Context, NodeTypes, OtherNodeIOETypes, LastNodeIOETypes> Builder<Input, Output, Error, Context, NodeTypes, (OtherNodeIOETypes, LastNodeIOETypes)>
where Input: Send + Clone, Error: Send, Context: Fork + Join + Send,

Source

pub fn add_node<NodeType, NodeInput, NodeOutput, NodeError>( self, node: NodeType, ) -> Builder<Input, Output, Error, Context, (NodeTypes, NodeType), ((OtherNodeIOETypes, LastNodeIOETypes), (NodeInput, NodeOutput<NodeOutput>, NodeError))>
where Input: Into<NodeInput>, NodeError: Into<Error>, NodeType: Node<NodeInput, NodeOutputStruct<NodeOutput>, NodeError, Context> + Send + Sync + Clone, NodeOutput: Send,

Adds a new node.

The new node must satisfy:

  • Self: Node<NodeInputType, NodeOutput<NodeOutputType>, NodeErrorType, _>
  • Input: Into<NodeInputType>,
  • NodeErrorType: Into<Error>,
§Returns

A new Builder with the added node.

Source

pub fn build<J, ChainRunOutput>( self, joiner: J, ) -> Flow<Input, Output, Error, Context, ChainRunOutput, J, NodeTypes, (OtherNodeIOETypes, LastNodeIOETypes)>
where for<'a> J: Joiner<'a, ChainRunOutput, Output, Error, Context>, NodeTypes: ChainRun<Input, Result<ChainRunOutput, Error>, Context, (OtherNodeIOETypes, LastNodeIOETypes)>,

Finalizes the builder and produces a ParallelFlow instance.

The joiner must satisfy:

  • Self: Joiner<'_, NodesOutputs, Output, Error, _>

When using closure as a joiner it always needs:

  • to be an async closure - because of lifetimes
  • for context to:
    • have the type of a context specified when using context - because it cannot infer the type
      or
    • have the context specified as _: &mut _ when not using context - because it cannot satisfy that Joiner is implemented
§Examples
// ...
.build(async |_, _: &mut _| {
    Ok(NodeOutput::Ok(120))
});
// ...
.build(async |_, ctx: &mut Context| {
    let _forked_ctx = ctx.fork();
    Ok(NodeOutput::Ok(120))
});

Trait Implementations§

Source§

impl<Input, Output, Error, Context, NodeTypes, NodeIOETypes> Debug for Builder<Input, Output, Error, Context, NodeTypes, NodeIOETypes>
where NodeTypes: ChainDebug, Input: Send + Clone, Error: Send, Context: Fork + Join + Send,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Input, Output, Error, Context> Default for Builder<Input, Output, Error, Context>
where Input: Send + Clone, Error: Send, Context: Fork + Join + Send,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<Input, Output, Error, Context, NodeTypes, NodeIOETypes> Freeze for Builder<Input, Output, Error, Context, NodeTypes, NodeIOETypes>
where NodeTypes: Freeze,

§

impl<Input, Output, Error, Context, NodeTypes, NodeIOETypes> RefUnwindSafe for Builder<Input, Output, Error, Context, NodeTypes, NodeIOETypes>
where NodeTypes: RefUnwindSafe,

§

impl<Input, Output, Error, Context, NodeTypes, NodeIOETypes> Send for Builder<Input, Output, Error, Context, NodeTypes, NodeIOETypes>
where NodeTypes: Send,

§

impl<Input, Output, Error, Context, NodeTypes, NodeIOETypes> Sync for Builder<Input, Output, Error, Context, NodeTypes, NodeIOETypes>
where NodeTypes: Sync,

§

impl<Input, Output, Error, Context, NodeTypes, NodeIOETypes> Unpin for Builder<Input, Output, Error, Context, NodeTypes, NodeIOETypes>
where NodeTypes: Unpin,

§

impl<Input, Output, Error, Context, NodeTypes, NodeIOETypes> UnwindSafe for Builder<Input, Output, Error, Context, NodeTypes, NodeIOETypes>
where NodeTypes: 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V