pub struct Cx { /* private fields */ }Expand description
Capability context handle.
Cheaply cloneable. Check is_cancelled() at natural yield points
(loop iterations, before I/O, before expensive computation).
Implementations§
Source§impl Cx
impl Cx
Sourcepub fn background() -> (Self, CxController)
pub fn background() -> (Self, CxController)
Create a root context with no deadline.
Sourcepub fn with_deadline(deadline: Duration) -> (Self, CxController)
pub fn with_deadline(deadline: Duration) -> (Self, CxController)
Create a root context with a deadline.
Sourcepub fn lab(clock: &LabClock) -> (Self, CxController)
pub fn lab(clock: &LabClock) -> (Self, CxController)
Create a root context using a LabClock for deterministic testing.
Sourcepub fn lab_with_deadline(
clock: &LabClock,
deadline: Duration,
) -> (Self, CxController)
pub fn lab_with_deadline( clock: &LabClock, deadline: Duration, ) -> (Self, CxController)
Create a lab context with a deadline.
Sourcepub fn child(&self, deadline: Duration) -> (Self, CxController)
pub fn child(&self, deadline: Duration) -> (Self, CxController)
Derive a child context with a tighter deadline.
The effective deadline is min(parent.deadline(), child_deadline).
Cancelling the parent also cancels the child (checked via chain walk).
Sourcepub fn child_inherit(&self) -> (Self, CxController)
pub fn child_inherit(&self) -> (Self, CxController)
Derive a child context that inherits the parent deadline.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check if this context (or any ancestor) has been cancelled.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if the deadline has passed.
Sourcepub fn deadline(&self) -> Option<Duration>
pub fn deadline(&self) -> Option<Duration>
Return the effective deadline as a Duration from context creation,
considering the full parent chain. Returns None if no deadline is set.
Sourcepub fn remaining(&self) -> Option<Duration>
pub fn remaining(&self) -> Option<Duration>
Remaining time until deadline (saturates to zero, never negative).
Returns None if no deadline is set.
Sourcepub fn remaining_us(&self) -> Option<u64>
pub fn remaining_us(&self) -> Option<u64>
Remaining time in microseconds, or None if no deadline.