Skip to main content

Cx

Struct Cx 

Source
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 Cx<FullCaps>

Source

pub fn new() -> Self

Source§

impl<Caps: SubsetOf<All>> Cx<Caps>

Source

pub fn with_budget(budget: Budget) -> Self

Source

pub fn budget(&self) -> Budget

Source

pub fn trace_id(&self) -> u64

The trace ID for this context (0 = unset).

Source

pub fn decision_id(&self) -> u64

The decision ID for this context (0 = unset).

Source

pub fn policy_id(&self) -> u64

The policy ID for this context (0 = unset).

Source

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.

Source

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.

Source

pub fn with_policy_id(self, policy_id: u64) -> Self

Return a new context with only the policy_id changed.

Source

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.

Source

pub fn cleanup_scope(&self) -> Self

Returns a cleanup scope that uses Budget::MINIMAL.

Source

pub fn restrict<NewCaps>(&self) -> Cx<NewCaps>
where NewCaps: SubsetOf<All> + SubsetOf<Caps>,

Re-type this context to a narrower capability set.

This is zero-cost at runtime and shares cancellation state.

Source

pub fn is_cancel_requested(&self) -> bool

Source

pub fn cancel(&self)

Request cancellation with the default reason (UserInterrupt).

Propagates to all child contexts per INV-CANCEL-PROPAGATES.

Source

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.

Source

pub fn cancel_state(&self) -> CancelState

Current state in the cancellation lifecycle.

Source

pub fn cancel_reason(&self) -> Option<CancelReason>

The strongest cancellation reason set so far, if any.

Source

pub fn transition_to_running(&self)

Transition from Created to Running.

Source

pub fn transition_to_finalizing(&self)

Transition from Cancelling to Finalizing.

Source

pub fn transition_to_completed(&self)

Transition to Completed (from Finalizing or Running).

Source

pub fn set_eprocess_oracle(&self, oracle: Arc<EProcessOracle>)

Attach an e-process oracle used by Self::checkpoint.

Source

pub fn clear_eprocess_oracle(&self)

Remove the currently attached e-process oracle.

Source

pub fn set_native_cx(&self, native_cx: NativeCx)

Attach a native asupersync context used by Self::checkpoint.

Source

pub fn attached_native_cx(&self) -> Option<NativeCx>

Return the attached native asupersync context, if one exists.

Source

pub fn clear_native_cx(&self)

Remove the currently attached native asupersync context.

Source

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.

Source

pub fn checkpoint_with(&self, msg: impl Into<String>) -> Result<()>

Check for cancellation and record a progress message.

Source

pub fn last_checkpoint_message(&self) -> Option<String>

Source

pub fn last_eprocess_decision(&self) -> Option<EProcessDecision>

Most recent e-process decision recorded during Self::checkpoint.

Source

pub fn last_eprocess_snapshot(&self) -> Option<EProcessSnapshot>

Snapshot portion of the most recent e-process decision.

Source

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).

Source

pub fn mask_depth(&self) -> u32

Current mask nesting depth.

Source

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.

Source

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.

Source

pub fn set_unix_millis_for_testing(&self, millis: u64)
where Caps: HasTime,

Set a deterministic unix time for tests.

Source

pub fn current_time_julian_day(&self) -> f64
where Caps: HasTime,

Return current time as a Julian day (via deterministic unix millis).

Trait Implementations§

Source§

impl<Caps: SubsetOf<All>> Clone for Cx<Caps>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Caps: Debug + SubsetOf<All>> Debug for Cx<Caps>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Cx<FullCaps>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<Caps> Freeze for Cx<Caps>

§

impl<Caps = CapSet<true, true, true, true, true>> !RefUnwindSafe for Cx<Caps>

§

impl<Caps> Send for Cx<Caps>

§

impl<Caps> Sync for Cx<Caps>

§

impl<Caps> Unpin for Cx<Caps>

§

impl<Caps> UnsafeUnpin for Cx<Caps>

§

impl<Caps = CapSet<true, true, true, true, true>> !UnwindSafe for Cx<Caps>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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