pub trait Node: Send + Sync {
// Required method
fn run<'life0, 'async_trait>(
&'life0 self,
snapshot: StateSnapshot,
ctx: NodeContext,
) -> Pin<Box<dyn Future<Output = Result<NodePartial, NodeError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Core trait for executable workflow nodes.
A node receives the current state snapshot and execution context, performs its work, and returns partial state updates.
§Error handling
- Fatal errors: return
Err(NodeError)to halt execution. - Recoverable errors: push into
NodePartial::errorsand returnOk.
§Example
use weavegraph::node::{Node, NodeContext, NodePartial, NodeError};
use weavegraph::state::StateSnapshot;
use async_trait::async_trait;
struct GreetNode;
#[async_trait]
impl Node for GreetNode {
async fn run(&self, _snapshot: StateSnapshot, ctx: NodeContext) -> Result<NodePartial, NodeError> {
ctx.emit("greet", "hello")?;
Ok(NodePartial::default())
}
}Required Methods§
Sourcefn run<'life0, 'async_trait>(
&'life0 self,
snapshot: StateSnapshot,
ctx: NodeContext,
) -> Pin<Box<dyn Future<Output = Result<NodePartial, NodeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn run<'life0, 'async_trait>(
&'life0 self,
snapshot: StateSnapshot,
ctx: NodeContext,
) -> Pin<Box<dyn Future<Output = Result<NodePartial, NodeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Execute this node with the given state snapshot and context.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".