Skip to main content

NodeContext

Struct NodeContext 

Source
pub struct NodeContext<'a, S: WorkflowState = State> { /* private fields */ }
Expand description

节点能力视图 — 向后兼容,节点能做的三件事:读 State、记录 Mutation、发射 Stream。

§设计原则

NodeContext 是 Runtime 的能力视图,不是 Runtime 的拥有者。

  • 节点只借用,不拥有。零复制透传给子组件
  • 禁止放入:RuntimeEventEmitter、TraceId、SpanId、GraphHandle、ExecutorConfig
  • 不提供 state_mut() — 节点只能通过 record() 声明变更意图
  • 组合节点(如 ParallelNode)使用 replace_state() 整体替换状态

§泛型参数

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

Implementations§

Source§

impl<S: WorkflowState> NodeContext<'_, S>

Source

pub fn state(&self) -> &S

获取类型化状态(只读)。

Source

pub fn replace_state(&mut self, new_state: S)

替换整个状态(仅组合节点使用,如 ParallelNode)。

这是组合节点合并子分支结果后的 sanctioned API。 普通节点应使用 record() 声明变更意图。

替换后,Engine 持有的状态直接变为 new_state。 不会触发 Mutation 记录(因为这是整体替换,不是增量变更)。

Source

pub fn record(&mut self, mutation: S::Mutation)

记录一个 Mutation(强类型状态变更命令)到缓冲。

这是节点变更状态的唯一入口。 零序列化开销 — 直接存储 S::Mutation

Executor 在节点执行后统一消费并 apply 到 State。

Source

pub fn emit(&self, chunk: StreamChunk)

发射数据面事件(无 stream 则静默丢弃)。

Source

pub fn is_cancelled(&self) -> bool

检查是否已取消。

Source

pub fn cancel_token(&self) -> &CancellationToken

获取取消令牌引用。

Source

pub fn goto(&mut self, target: impl Into<String>)

跳转到指定节点。

Source

pub fn end(&mut self)

结束执行。

Source

pub fn pause(&mut self, barrier_id: BarrierId, timeout: Option<Duration>)

Barrier 挂起。

Source

pub fn set_token_cost(&mut self, cost: f64)

设置 token 成本。

Source

pub fn set_has_side_effects(&mut self)

标记有副作用。

Auto Trait Implementations§

§

impl<'a, S = State> !RefUnwindSafe for NodeContext<'a, S>

§

impl<'a, S = State> !UnwindSafe for NodeContext<'a, S>

§

impl<'a, S> Freeze for NodeContext<'a, S>

§

impl<'a, S> Send for NodeContext<'a, S>

§

impl<'a, S> Sync for NodeContext<'a, S>

§

impl<'a, S> Unpin for NodeContext<'a, S>

§

impl<'a, S> UnsafeUnpin for NodeContext<'a, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more