pub struct Deadline(/* private fields */);Expand description
A point on a clock’s monotonic timeline, in milliseconds.
Caller-driven components report deadlines so the host knows how long it may
idle before polling again. A deadline is only comparable to Now samples
from the same Clock, since monotonic epochs are arbitrary.
Ordering is chronological, so the earliest deadline in a collection is its
minimum and NEVER sorts last.
§Absent versus distant deadlines
“Nothing scheduled” is expressed as Option::None, not as NEVER. NEVER
is the saturating result of arithmetic that overflows past the end of the
timeline, and it never expires.
Implementations§
Source§impl Deadline
impl Deadline
Sourcepub const NEVER: Self
pub const NEVER: Self
A deadline that never expires.
Produced by saturating arithmetic such as
Now::deadline_after with a huge delay.
Sourcepub const IMMEDIATE: Self
pub const IMMEDIATE: Self
A deadline that has already expired.
Expired at every point on every timeline, so a component with work buffered can report “poll me again without idling” without knowing what the host’s clock currently reads.
Sourcepub const fn from_millis(millis: u64) -> Self
pub const fn from_millis(millis: u64) -> Self
Creates a deadline that expires when monotonic time reaches millis.
Sourcepub const fn as_millis(self) -> u64
pub const fn as_millis(self) -> u64
Returns the monotonic milliseconds value this deadline expires at.
Sourcepub const fn is_expired_at(self, now: Now) -> bool
pub const fn is_expired_at(self, now: Now) -> bool
Returns whether this deadline has expired as of now.
NEVER is never expired, even at the end of the
timeline.
Sourcepub const fn millis_until(self, now: Now) -> u64
pub const fn millis_until(self, now: Now) -> u64
Returns the milliseconds remaining until this deadline, or zero if it has already expired.
NEVER always reports u64::MAX remaining, however far
monotonic time has advanced, so it stays consistent with
is_expired_at never reporting it as due.
Sourcepub const fn saturating_add_millis(self, millis: u64) -> Self
pub const fn saturating_add_millis(self, millis: u64) -> Self
Returns a deadline millis later, saturating at
NEVER.
Sourcepub const fn earliest(self, other: Self) -> Self
pub const fn earliest(self, other: Self) -> Self
Returns whichever of the two deadlines comes first.
Sourcepub const fn earliest_opt(
left: Option<Self>,
right: Option<Self>,
) -> Option<Self>
pub const fn earliest_opt( left: Option<Self>, right: Option<Self>, ) -> Option<Self>
Merges two optional deadlines, keeping whichever comes first.
Useful for folding the deadlines of several subsystems into the one a runtime reports to its host.