impl_node_output

Macro impl_node_output 

Source
macro_rules! impl_node_output {
    ($node:ty, $input:ty, $output:ty, $error:ty $(,$param:ident: $bound0:ident $(+$bound:ident)*)*) => { ... };
}
Expand description

Implements the Node trait for a type whose output needs to be wrapped in NodeOutput.

It automatically generates an implementation of:

impl<Context> Node<Input, NodeOutput<Output>, Error, Context> for NodeType

From an existing implementation of:

impl<Context> Node<Input, Output, Error, Context> for NodeType

This macro adds a Node implementation that returns NodeOutput<T>. It works by wrapping an existing implementation of Node that returns Output, turning it into NodeOutput<Output>.

§Parameters

  • $node: The node type to add an implementation for.
  • $input, $output, $error: Input, Output and Error type parameters for the node.
  • $param: $bound0 + $bound: Optional trait bounds for generics.

See also Node, NodeOutput.

§Examples

use node_flow::{impl_node_output, node::{Node, NodeOutput}};

struct ExampleNode;

impl<Context: Send> Node<i32, i32, String, Context> for ExampleNode {
    async fn run(&mut self, input: i32, _context: &mut Context) -> Result<i32, String> {
        Ok(input + 1)
    }
}

// Automatically implement Node<i32, NodeOutput<i32>, String, _> for ExampleNode.
impl_node_output!(ExampleNode, i32, i32, String);