Skip to main content

NodeContext

Struct NodeContext 

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

节点上下文 — Runtime Handle(运行时句柄)。

§泛型参数

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

§设计原则

NodeContext 是 Runtime Handle,不是 Runtime State。

  • 节点只借用,不拥有。零复制透传给子组件
  • 禁止放入:RuntimeEventEmitter、TraceId、SpanId、GraphHandle、ExecutorConfig

§Effects 缓冲(v0.4+)

effects 字段收集节点产生的 Effect(领域事件), 供上层(如 Executor)统一 apply 到 Typed State。

Implementations§

Source§

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

Source

pub fn new( state: &'a mut S, branch: &'a mut BranchState, stream: Option<&'a StreamEmitter>, ) -> Self

创建新的 NodeContext。

Source

pub fn state(&self) -> &S

获取类型化状态引用。

Source

pub fn state_mut(&mut self) -> &mut S

获取类型化状态可变引用。

Source

pub fn branch(&self) -> &BranchState

获取底层 BranchState 引用(用于 fork 等操作)。

Source

pub fn branch_mut(&mut self) -> &mut BranchState

获取底层 BranchState 可变引用。

Source

pub fn emit(&self, chunk: StreamChunk)

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

Source

pub fn emit_flow_event(&mut self, event: FlowEvent)

发射控制面 FlowEvent(缓冲到 NodeContext,供 Executor 收集转发)。

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)

标记有副作用。

Source

pub fn emit_effect(&mut self, effect: S::Effect)

发射一个 Effect(强类型领域事件)到缓冲。

零序列化开销 — 直接存储 S::Effect

Source

pub fn consume_effects(&mut self) -> Vec<S::Effect>

消费 Effect 缓冲(返回所有收集的 Effect)。

Source

pub fn effects_len(&self) -> usize

获取已收集的 Effect 数量(不消费)。

Source

pub fn take_control(&mut self) -> (NextAction, Option<ExecutionSignal>)

消费控制信号(Executor 调用)。

Source

pub fn take_metadata(&mut self) -> NodeMetadata

获取元数据(Executor 调用)。

Source

pub fn stream(&self) -> Option<&'a StreamEmitter>

获取数据面发射器引用。

Source

pub fn take_flow_events(&mut self) -> Vec<FlowEvent>

消费 FlowEvent 缓冲(Executor 调用)。

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>
where <S as WorkflowState>::Effect: Unpin,

§

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