Skip to main content

FlowNode

Trait FlowNode 

Source
pub trait FlowNode<S: WorkflowState = State>: Send + Sync {
    // Required method
    fn execute<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        ctx: &'life1 mut NodeContext<'life2, S>,
    ) -> Pin<Box<dyn Future<Output = Result<(), GraphError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

v04 节点执行 trait — Context 驱动一切。

统一原则 — 节点不返回业务数据,只返回 Result<(), GraphError>

  • State → ctx.state() / ctx.state_mut()
  • Effects → ctx.emit_effect()
  • Stream → ctx.emit()
  • Metadata → ctx.set_token_cost()
  • Control → ctx.goto() / ctx.end() / ctx.pause()

§泛型参数

  • S — 类型化状态(默认 State = HashMap,向后兼容)

Required Methods§

Source

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

执行节点逻辑。

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§