pub struct LifecycleContext { /* private fields */ }Expand description
一次 Tick 的不可变 correlation 上下文。
with_* 方法均返回新值;调用方可以在 T1/T2/T3/T4/T5 间传递上下文,
不需要全局 carrier 或 task-local 状态。current_stage 的父阶段恒为 T1,
使同一 Tick 内的本地子树不会意外嵌套到前一个效果。
Implementations§
Source§impl LifecycleContext
impl LifecycleContext
Sourcepub fn new(
tick_id: u64,
parent_tick_id: Option<u64>,
carrier: Option<TraceCarrier>,
) -> LifecycleContext
pub fn new( tick_id: u64, parent_tick_id: Option<u64>, carrier: Option<TraceCarrier>, ) -> LifecycleContext
创建 T1 根上下文;网络能力默认关闭,避免缺能力时伪造 network span。
Sourcepub fn root(
tick_id: u64,
parent_tick_id: Option<u64>,
carrier: Option<TraceCarrier>,
) -> LifecycleContext
pub fn root( tick_id: u64, parent_tick_id: Option<u64>, carrier: Option<TraceCarrier>, ) -> LifecycleContext
创建带父 Tick 的 T1 上下文,作为 engine 的语义化构造别名。
Sourcepub const fn parent_tick_id(&self) -> Option<u64>
pub const fn parent_tick_id(&self) -> Option<u64>
返回上游 Tick ID;没有可证明的上游时保持 None。
Sourcepub fn carrier(&self) -> Option<&TraceCarrier>
pub fn carrier(&self) -> Option<&TraceCarrier>
返回显式 carrier 的只读引用。
Sourcepub fn span_parent(&self) -> Option<&TraceCarrier>
pub fn span_parent(&self) -> Option<&TraceCarrier>
返回当前 Tick 内部 T1 span 的显式 parent carrier;没有 OTel 时保持 None。
Sourcepub fn with_span_parent(
&self,
span_parent: Option<TraceCarrier>,
) -> LifecycleContext
pub fn with_span_parent( &self, span_parent: Option<TraceCarrier>, ) -> LifecycleContext
返回新的上下文并绑定本 Tick 的内部 span parent,不写入全局或 task-local 状态。
Sourcepub fn otel_parent(&self) -> Option<&TraceCarrier>
pub fn otel_parent(&self) -> Option<&TraceCarrier>
选择异步子节点的显式 parent;内部 T1 优先,外部 W3C carrier 仅作根回退。
Sourcepub const fn current_stage(&self) -> LifecycleStage
pub const fn current_stage(&self) -> LifecycleStage
返回当前生命周期阶段。
Sourcepub const fn parent_stage(&self) -> LifecycleStage
pub const fn parent_stage(&self) -> LifecycleStage
返回当前阶段在 T1 根下的挂载点。
Sourcepub const fn stage_status(&self, stage: LifecycleStage) -> LifecycleStatus
pub const fn stage_status(&self, stage: LifecycleStage) -> LifecycleStatus
读取五阶段状态,不会修改上下文。
Sourcepub fn with_stage_status(
&self,
stage: LifecycleStage,
status: LifecycleStatus,
) -> LifecycleContext
pub fn with_stage_status( &self, stage: LifecycleStage, status: LifecycleStatus, ) -> LifecycleContext
设置阶段状态并返回新上下文。
Sourcepub const fn has_capability(&self, capability: LifecycleCapability) -> bool
pub const fn has_capability(&self, capability: LifecycleCapability) -> bool
读取能力是否存在。
Sourcepub const fn capability_status(
&self,
capability: LifecycleCapability,
) -> LifecycleStatus
pub const fn capability_status( &self, capability: LifecycleCapability, ) -> LifecycleStatus
读取能力状态;未提供能力时固定返回 NotApplicable。
Sourcepub fn with_capability(
&self,
capability: LifecycleCapability,
enabled: bool,
) -> LifecycleContext
pub fn with_capability( &self, capability: LifecycleCapability, enabled: bool, ) -> LifecycleContext
设置能力存在性;关闭能力时状态自动收敛到 NotApplicable。
Sourcepub fn with_capability_status(
&self,
capability: LifecycleCapability,
status: LifecycleStatus,
) -> LifecycleContext
pub fn with_capability_status( &self, capability: LifecycleCapability, status: LifecycleStatus, ) -> LifecycleContext
设置能力状态并返回新上下文;NotApplicable 会同时关闭该能力。
Sourcepub fn local_stage(&self, stage: LifecycleStage) -> LifecycleContext
pub fn local_stage(&self, stage: LifecycleStage) -> LifecycleContext
构造同一 Tick 的局部阶段上下文,所有局部节点直接挂到 T1。
Trait Implementations§
Source§impl Clone for LifecycleContext
impl Clone for LifecycleContext
Source§fn clone(&self) -> LifecycleContext
fn clone(&self) -> LifecycleContext
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LifecycleContext
impl Debug for LifecycleContext
Source§impl Default for LifecycleContext
impl Default for LifecycleContext
Source§fn default() -> LifecycleContext
fn default() -> LifecycleContext
创建 synthetic root,供无 Tick 的测试/启动 effect 使用。
impl Eq for LifecycleContext
Source§impl PartialEq for LifecycleContext
impl PartialEq for LifecycleContext
impl StructuralPartialEq for LifecycleContext
Auto Trait Implementations§
impl Freeze for LifecycleContext
impl RefUnwindSafe for LifecycleContext
impl Send for LifecycleContext
impl Sync for LifecycleContext
impl Unpin for LifecycleContext
impl UnsafeUnpin for LifecycleContext
impl UnwindSafe for LifecycleContext
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request