Skip to main content

Node

Trait Node 

Source
pub trait Node<S: GraphState>: Send + Sync {
    // Required method
    fn execute<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        state: &'life1 S,
        config: &'life2 RunnableConfig,
    ) -> Pin<Box<dyn Future<Output = Result<NodeOutput>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided methods
    fn name(&self) -> Option<&str> { ... }
    fn retry_policy(&self) -> RetryPolicy { ... }
}
Expand description

Trait for graph nodes.

Nodes are async functions that receive the current state and configuration, and return a state update or command.

§Type Parameters

  • S: The state type for this graph.

§Examples

ⓘ
use regula_core::{Node, NodeOutput, GraphState, RunnableConfig, Result};
use async_trait::async_trait;

struct MyNode;

#[async_trait]
impl<S: GraphState> Node<S> for MyNode {
    async fn execute(&self, state: &S, config: &RunnableConfig) -> Result<NodeOutput> {
        // Process state and return update
        Ok(NodeOutput::update(serde_json::json!({
            "counter": 42
        })))
    }
}

Required Methods§

Source

fn execute<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, state: &'life1 S, config: &'life2 RunnableConfig, ) -> Pin<Box<dyn Future<Output = Result<NodeOutput>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Execute the node with the current state.

§Arguments
  • state: The current graph state.
  • config: Runtime configuration and context.
§Returns

A NodeOutput containing state updates and/or routing commands.

Provided Methods§

Source

fn name(&self) -> Option<&str>

Get the name of this node (for debugging/tracing).

Source

fn retry_policy(&self) -> RetryPolicy

Check if this node should be retried on failure.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<S, F, Fut> Node<S> for FnNode<S, F, Fut>
where S: GraphState, F: Fn(&S, &RunnableConfig) -> Fut + Send + Sync, Fut: Future<Output = Result<NodeOutput>> + Send,