Node

Trait Node 

Source
pub trait Node<Input, Output, Error, Context> {
    // Required method
    fn run(
        &mut self,
        input: Input,
        context: &mut Context,
    ) -> impl Future<Output = Result<Output, Error>> + Send;

    // Provided method
    fn describe(&self) -> Description
       where Self: Sized { ... }
}
Expand description

The Node trait serves as the core building block.

It defines how Input is processed into an Output (and Error) with a given Context.

§Type Parameters

  • Input: The type of data consumed by the node.
  • Output: The type of data produced by the node.
  • Error: The type representing possible errors.
  • Context: The type of context used during execution (it should always be a generic).

§Examples

impl<Context: Send> Node<i32, NodeOutput<String>, MyError, Context> for ExampleNode {
    async fn run(
        &mut self,
        input: i32,
        _context: &mut Context,
    ) -> Result<NodeOutput<String>, MyError> {
        Ok(NodeOutput::Ok(format!("Processed: {}", input)))
    }

    fn describe(&self) -> Description {
        Description::new_node::<Self, i32, String, MyError, Context>(self)
            .with_description("My example node")
    }
}

Required Methods§

Source

fn run( &mut self, input: Input, context: &mut Context, ) -> impl Future<Output = Result<Output, Error>> + Send

Runs the node.

This method performs the node’s main computation or transformation logic.

§Parameters
  • input: The input data to process.
  • context: Mutable reference to a context, which may be used for configuration, logging, or shared state.
§Returns

A Future that resolves to a Result<Output, Error>.

§Examples
impl<Context: Send> Node<i32, String, MyError, Context> for ExampleNode {
    async fn run(
        &mut self,
        input: i32,
        _context: &mut Context,
    ) -> Result<String, MyError> {
        Ok(format!("Processed: {}", input))
    }
}

Provided Methods§

Source

fn describe(&self) -> Description
where Self: Sized,

Describes this node, its type signature and other specifics.

See Description for more details.

§Examples
impl<Context: Send> Node<i32, NodeOutput<String>, MyError, Context> for ExampleNode {
    async fn run(&mut self, input: i32, _context: &mut Context)
        -> Result<NodeOutput<String>, MyError> { todo!() }

    fn describe(&self) -> Description {
        Description::new_node::<Self, i32, String, MyError, Context>(self)
            .with_description("My example node")
    }
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<Input, Error, Context, NodeType, NodeOutput, NodeError> Node<Input, NodeOutput<Input>, Error, Context> for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>
where NodeType: Node<Input, NodeOutput, NodeError, Context> + Clone + Send + 'static, Context: SpawnAsync + Fork + Send + 'static, Input: Clone + Send + 'static,

Source§

impl<Input, Output, Error, Context, ChainRunOutput, J, NodeTypes, NodeIOETypes> Node<Input, NodeOutput<Output>, Error, Context> for ParallelFlow<Input, Output, Error, Context, ChainRunOutput, J, NodeTypes, NodeIOETypes>
where Input: Send, Context: Send, for<'a> J: Joiner<'a, ChainRunOutput, Output, Error, Context>, NodeTypes: ChainRun<Input, Result<ChainRunOutput, Error>, Context, NodeIOETypes> + ChainDescribe<Context, NodeIOETypes> + Send + Sync,

Source§

impl<Input, Output, Error, Context, InnerData, R> Node<Input, NodeOutput<Output>, Error, Context> for FnFlow<Input, Output, Error, Context, InnerData, R>
where InnerData: Clone, for<'a> R: Runner<'a, Input, Output, Error, Context, InnerData>,

Source§

impl<Input, Output, Error, Context, NodeTypes, NodeIOETypes> Node<Input, NodeOutput<Output>, Error, Context> for OneOfParallelFlow<Input, Output, Error, Context, NodeTypes, NodeIOETypes>
where NodeTypes: ChainRun<Input, Result<NodeOutput<Output>, Error>, Context, NodeIOETypes> + ChainDescribe<Context, NodeIOETypes>,

Source§

impl<Input, Output, Error, Context, NodeTypes, NodeIOETypes> Node<Input, NodeOutput<Output>, Error, Context> for OneOfSequentialFlow<Input, Output, Error, Context, NodeTypes, NodeIOETypes>
where NodeTypes: ChainRun<Input, Result<NodeOutput<Output>, Error>, Context, NodeIOETypes> + ChainDescribe<Context, NodeIOETypes>,

Source§

impl<Input, Output, Error, Context, NodeTypes, NodeIOETypes> Node<Input, NodeOutput<Output>, Error, Context> for SequentialFlow<Input, Output, Error, Context, NodeTypes, NodeIOETypes>
where NodeTypes: ChainRun<Input, Result<NodeOutput<Output>, Error>, Context, NodeIOETypes> + ChainDescribe<Context, NodeIOETypes>,