pub struct LeafContext<'a, S: WorkflowState = State> { /* private fields */ }Expand description
Leaf 节点能力视图 — 纯借用,不拥有任何状态。
设计原则:
- 只能读 State(
&S,不可变引用) - 只能 emit Mutation(借用在 Engine 的 mutations buffer)
- 只能 emit Stream
- 不能 replace_state / clone_state / fork / merge
与 NodeContext 的区别:
- NodeContext 持有
&mut S(可变引用),Composite 节点可用 replace_state() - LeafContext 持有
&S(只读引用),编译期保证不能修改 State
Implementations§
Source§impl<S: WorkflowState> LeafContext<'_, S>
impl<S: WorkflowState> LeafContext<'_, S>
Sourcepub fn record(&mut self, mutation: S::Mutation)
pub fn record(&mut self, mutation: S::Mutation)
记录一个 Mutation(强类型状态变更命令)到缓冲。
这是 Leaf 节点变更状态的唯一入口。
Sourcepub fn emit(&self, chunk: StreamChunk)
pub fn emit(&self, chunk: StreamChunk)
发射数据面事件(无 stream 则静默丢弃)。
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
检查是否已取消。
Sourcepub fn cancel_token(&self) -> &CancellationToken
pub fn cancel_token(&self) -> &CancellationToken
获取取消令牌引用。
Sourcepub fn set_token_cost(&mut self, cost: f64)
pub fn set_token_cost(&mut self, cost: f64)
设置 token 成本。
Sourcepub fn set_has_side_effects(&mut self)
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more