Skip to main content

Node

Trait Node 

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

    // Provided methods
    fn validate_against(&self, _parent: &StateSchema) -> Result<(), GraphError> { ... }
    fn validate(&self) -> Result<(), GraphError> { ... }
    fn execute_stream<'a>(
        &'a self,
        ctx: &'a NodeContext,
    ) -> Pin<Box<dyn Stream<Item = Result<StreamEvent, GraphError>> + Send + 'a>> { ... }
}
Available on crate feature graph only.
Expand description

A node in the graph

Required Methods§

Source

fn name(&self) -> &str

Node identifier

Source

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

Execute the node and return state updates

Provided Methods§

Source

fn validate_against(&self, _parent: &StateSchema) -> Result<(), GraphError>

Rejects a node that cannot execute, before the graph runs.

Called for every node by StateGraph::compile, so a configuration whose backend is unavailable fails while the graph is being built rather than part-way through a run, when earlier nodes may already have had side effects.

§Errors

Returns an error describing what is unavailable. The default accepts the node. Checks this node against the schema of the graph that holds it.

Called by StateGraph::compile for every node, so a node that has requirements on its parent states them before anything runs. Defaults to accepting any parent.

SubgraphNode uses this to reject a channel mapping that names a channel neither side declares.

Source

fn validate(&self) -> Result<(), GraphError>

Source

fn execute_stream<'a>( &'a self, ctx: &'a NodeContext, ) -> Pin<Box<dyn Stream<Item = Result<StreamEvent, GraphError>> + Send + 'a>>

Streams execution events for this node.

An implementation must report the node’s state updates by yielding a StreamEvent::Updates event, because a streaming executor takes the updates from this stream rather than executing the node a second time. The default implementation wraps Node::execute and does so.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§