pub struct Cx<Caps: SubsetOf<All> = FullCaps> { /* private fields */ }Expand description
Capability context passed through all effectful operations.
Carries tracing identifiers (trace_id, decision_id, policy_id) that
propagate through all context derivations (clone, restrict, scope, child).
A value of 0 means “unset / not assigned”.
Implementations§
Source§impl<Caps: SubsetOf<All>> Cx<Caps>
impl<Caps: SubsetOf<All>> Cx<Caps>
pub fn with_budget(budget: Budget) -> Self
pub fn budget(&self) -> Budget
Sourcepub fn decision_id(&self) -> u64
pub fn decision_id(&self) -> u64
The decision ID for this context (0 = unset).
Sourcepub fn with_trace_context(
self,
trace_id: u64,
decision_id: u64,
policy_id: u64,
) -> Self
pub fn with_trace_context( self, trace_id: u64, decision_id: u64, policy_id: u64, ) -> Self
Set all three tracing identifiers at once.
Typically called once when a connection or request is initialized.
Sourcepub fn with_decision_id(self, decision_id: u64) -> Self
pub fn with_decision_id(self, decision_id: u64) -> Self
Return a new context with only the decision_id changed.
Used when starting a new operation within the same trace.
Sourcepub fn with_policy_id(self, policy_id: u64) -> Self
pub fn with_policy_id(self, policy_id: u64) -> Self
Return a new context with only the policy_id changed.
Sourcepub fn scope_with_budget(&self, child: Budget) -> Self
pub fn scope_with_budget(&self, child: Budget) -> Self
Returns a view of this context with a tighter effective budget.
The effective budget is computed as self.budget.meet(child), so the
child cannot loosen its parent’s constraints.
Tracing IDs propagate unchanged.
Sourcepub fn cleanup_scope(&self) -> Self
pub fn cleanup_scope(&self) -> Self
Returns a cleanup scope that uses Budget::MINIMAL.
Sourcepub fn restrict<NewCaps>(&self) -> Cx<NewCaps>
pub fn restrict<NewCaps>(&self) -> Cx<NewCaps>
Re-type this context to a narrower capability set.
This is zero-cost at runtime and shares cancellation state.
pub fn is_cancel_requested(&self) -> bool
Sourcepub fn cancel(&self)
pub fn cancel(&self)
Request cancellation with the default reason (UserInterrupt).
Propagates to all child contexts per INV-CANCEL-PROPAGATES.
Sourcepub fn cancel_with_reason(&self, reason: CancelReason)
pub fn cancel_with_reason(&self, reason: CancelReason)
Request cancellation with an explicit reason.
INV-CANCEL-IDEMPOTENT: the strongest reason wins; weaker reasons are ignored once a stronger one has been set.
INV-CANCEL-PROPAGATES: cancellation propagates to all descendants.
Sourcepub fn cancel_state(&self) -> CancelState
pub fn cancel_state(&self) -> CancelState
Current state in the cancellation lifecycle.
Sourcepub fn cancel_reason(&self) -> Option<CancelReason>
pub fn cancel_reason(&self) -> Option<CancelReason>
The strongest cancellation reason set so far, if any.
Sourcepub fn transition_to_running(&self)
pub fn transition_to_running(&self)
Transition from Created to Running.
Sourcepub fn transition_to_finalizing(&self)
pub fn transition_to_finalizing(&self)
Transition from Cancelling to Finalizing.
Sourcepub fn transition_to_completed(&self)
pub fn transition_to_completed(&self)
Transition to Completed (from Finalizing or Running).
Sourcepub fn set_eprocess_oracle(&self, oracle: Arc<EProcessOracle>)
pub fn set_eprocess_oracle(&self, oracle: Arc<EProcessOracle>)
Attach an e-process oracle used by Self::checkpoint.
Sourcepub fn clear_eprocess_oracle(&self)
pub fn clear_eprocess_oracle(&self)
Remove the currently attached e-process oracle.
Sourcepub fn set_native_cx(&self, native_cx: NativeCx)
pub fn set_native_cx(&self, native_cx: NativeCx)
Attach a native asupersync context used by Self::checkpoint.
Sourcepub fn attached_native_cx(&self) -> Option<NativeCx>
pub fn attached_native_cx(&self) -> Option<NativeCx>
Return the attached native asupersync context, if one exists.
Sourcepub fn clear_native_cx(&self)
pub fn clear_native_cx(&self)
Remove the currently attached native asupersync context.
Sourcepub fn checkpoint(&self) -> Result<()>
pub fn checkpoint(&self) -> Result<()>
Check for cancellation at a yield point.
Returns Ok(()) when not cancelled or when inside a masked section.
When cancellation is observed, transitions state from CancelRequested
to Cancelling.
Sourcepub fn checkpoint_with(&self, msg: impl Into<String>) -> Result<()>
pub fn checkpoint_with(&self, msg: impl Into<String>) -> Result<()>
Check for cancellation and record a progress message.
pub fn last_checkpoint_message(&self) -> Option<String>
Sourcepub fn last_eprocess_decision(&self) -> Option<EProcessDecision>
pub fn last_eprocess_decision(&self) -> Option<EProcessDecision>
Most recent e-process decision recorded during Self::checkpoint.
Sourcepub fn last_eprocess_snapshot(&self) -> Option<EProcessSnapshot>
pub fn last_eprocess_snapshot(&self) -> Option<EProcessSnapshot>
Snapshot portion of the most recent e-process decision.
Sourcepub fn masked(&self) -> MaskGuard<'_>
pub fn masked(&self) -> MaskGuard<'_>
Enter a masked section where checkpoint() returns Ok(()) even if
cancellation is requested.
Returns a MaskGuard whose Drop restores the mask depth.
§Panics
Panics if nesting exceeds MAX_MASK_DEPTH (INV-MASK-BOUNDED).
Sourcepub fn mask_depth(&self) -> u32
pub fn mask_depth(&self) -> u32
Current mask nesting depth.
Sourcepub fn commit_section<R>(
&self,
poll_quota: u32,
body: impl FnOnce(&CommitCtx) -> R,
finalizer: impl FnOnce(),
) -> R
pub fn commit_section<R>( &self, poll_quota: u32, body: impl FnOnce(&CommitCtx) -> R, finalizer: impl FnOnce(), ) -> R
Execute a logically atomic commit section.
The section masks cancellation, enforces a poll quota bound, and
guarantees the finalizer runs even on cancellation or panic.
Sourcepub fn create_child(&self) -> Self
pub fn create_child(&self) -> Self
Create a child Cx that shares the parent’s budget but has
independent cancellation state. Cancelling the parent propagates
to this child. Tracing IDs propagate to the child.
Sourcepub fn set_unix_millis_for_testing(&self, millis: u64)where
Caps: HasTime,
pub fn set_unix_millis_for_testing(&self, millis: u64)where
Caps: HasTime,
Set a deterministic unix time for tests.
Sourcepub fn current_time_julian_day(&self) -> f64where
Caps: HasTime,
pub fn current_time_julian_day(&self) -> f64where
Caps: HasTime,
Return current time as a Julian day (via deterministic unix millis).