Skip to main content

Deadline

Struct Deadline 

Source
pub struct Deadline { /* private fields */ }
Expand description

A monotonic-time deadline for cooperative task cancellation.

Build one with Deadline::after (relative) or Deadline::at (absolute), then call Deadline::check_or_err between agent steps and Deadline::remaining when handing the timeout to a per-call API.

Deadlines are immutable. To tighten a deadline for a nested operation without touching the original, use Deadline::intersect.

Implementations§

Source§

impl Deadline

Source

pub fn after(duration: Duration) -> Self

Build a deadline that fires duration from now.

A Duration::ZERO produces an already-expired deadline, which is occasionally useful in tests.

Source

pub fn at(instant: Instant) -> Self

Build a deadline that fires at an exact monotonic instant.

Use this when you already have an Instant from another source (for example a parent task’s deadline expressed as an Instant).

Source

pub fn never() -> Self

A deadline that never fires.

Useful as a default for callers that may or may not want a cap. Self::remaining returns Duration::MAX, Self::expired is always false, and Self::check_or_err is a no-op.

Source

pub fn is_never(&self) -> bool

true if this deadline was built with Deadline::never.

Source

pub fn instant(&self) -> Option<Instant>

The absolute instant at which this deadline fires, if any.

Returns None for Deadline::never.

Source

pub fn expired(&self) -> bool

true once the current monotonic time is at or past the deadline.

Always false for Deadline::never.

Source

pub fn remaining(&self) -> Duration

Duration left until the deadline. Saturates at zero. Never negative.

Returns Duration::MAX for Deadline::never. Hand this to any timeout-taking API.

Source

pub fn remaining_seconds(&self) -> f64

Convenience for callers that want the remaining time as f64 seconds.

Returns f64::INFINITY for Deadline::never.

Source

pub fn elapsed(&self) -> Duration

Seconds since this deadline was constructed.

Survives an Self::intersect: the elapsed counter still measures against the original task start.

Source

pub fn check_or_err(&self) -> Result<(), DeadlineExceeded>

Cooperative check: return Err(DeadlineExceeded) if the deadline has passed.

No-op for Deadline::never. Call between agent steps.

Source

pub fn intersect(&self, other: &Deadline) -> Deadline

Return a new deadline that fires at the earlier of self and other.

created_at is preserved from self so Self::elapsed keeps measuring against the original task start, not the intersection point.

Source

pub fn intersect_after(&self, duration: Duration) -> Deadline

Convenience: intersect with a deadline duration from now.

Trait Implementations§

Source§

impl Clone for Deadline

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Deadline

Source§

impl Debug for Deadline

Source§

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

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

impl Default for Deadline

Source§

fn default() -> Self

Default deadline is Deadline::never. Useful in struct fields where “no cap” is the sane default.

Source§

impl Eq for Deadline

Source§

impl PartialEq for Deadline

Source§

fn eq(&self, other: &Self) -> bool

Two deadlines compare equal when they fire at the same instant (or both are never). created_at is not part of identity.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

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, 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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.