Skip to main content

LeafContext

Struct LeafContext 

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

Leaf 节点能力视图 — 纯借用,不拥有任何状态。

设计原则:

  • 只能读 State&S,不可变引用)
  • 只能 emit Mutation(借用在 Engine 的 mutations buffer)
  • 只能 emit Stream / FlowEvent
  • 不能 replace_state / clone_state / fork / merge

与 NodeContext 的区别:

  • NodeContext 持有 &mut S(可变引用),Composite 节点可用 replace_state()
  • LeafContext 持有 &S(只读引用),编译期保证不能修改 State

Implementations§

Source§

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

Source

pub fn state(&self) -> &S

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

Source

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

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

这是 Leaf 节点变更状态的唯一入口

Source

pub fn emit(&self, chunk: StreamChunk)

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

Source

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

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

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 LeafContext<'a, S>

§

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

§

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

§

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

§

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

§

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

§

impl<'a, S> UnsafeUnpin for LeafContext<'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