Skip to main content

Node

Trait Node 

Source
pub trait Node: Send + Sync {
    // Required method
    fn run<'life0, 'async_trait>(
        &'life0 self,
        ctx: NodeContext,
    ) -> Pin<Box<dyn Future<Output = Result<NodeOutput>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn name(&self) -> &str { ... }
    fn effect(&self) -> Effect { ... }
}
Expand description

The node trait: an async unit of computation over shared state.

Implement this directly for stateful nodes, or just pass an async closure to crate::graph::GraphBuilder::add_node — a blanket impl covers any Fn(NodeContext) -> impl Future<Output = Result<NodeOutput>> + Send + Sync.

Contract (enforced by the executor, documented here):

  • Nodes read state only from NodeContext::state (the super-step snapshot) and express all state changes via NodeOutput::updates.
  • Node logic must be idempotent: on interrupt-resume or partial-failure recovery the node re-executes from its start.

Required Methods§

Source

fn run<'life0, 'async_trait>( &'life0 self, ctx: NodeContext, ) -> Pin<Box<dyn Future<Output = Result<NodeOutput>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute the node against a super-step state snapshot.

Provided Methods§

Source

fn name(&self) -> &str

Human/log-friendly name. Closure nodes default to "anonymous"; the graph tracks nodes by the name given to add_node, which is the authoritative identity.

Source

fn effect(&self) -> Effect

The declared default effect classification of this node (Flight Recorder, R0.5): recorded on the node’s journal events and used by retry/replay policy.

The default is crate::record::Effect::Pure — a plain compute node over its state snapshot. Override honestly: a node that performs I/O or side effects inside run is not Pure, and misdeclaring it weakens replay fidelity (the journal will claim an effect was re-derivable when it was not). crate::remote::RemoteNode and the wasm-feature WasmNode override to NonIdempotent.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl Node for Arc<dyn Node>

Allow Arc<dyn Node> itself to be registered as a node (useful for sharing one node implementation across graphs).

Source§

fn name(&self) -> &str

Source§

fn run<'life0, 'async_trait>( &'life0 self, ctx: NodeContext, ) -> Pin<Box<dyn Future<Output = Result<NodeOutput>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Implementors§

Source§

impl Node for A2aNode

Source§

impl Node for RemoteNode

Source§

impl<F, Fut> Node for F
where F: Fn(NodeContext) -> Fut + Send + Sync, Fut: Future<Output = Result<NodeOutput>> + Send,

Blanket implementation for async closures/functions: Fn(NodeContext) -> impl Future<Output = Result<NodeOutput>>.