pub struct Instant(/* private fields */);Expand description
A monotonic clock instant whose arithmetic cannot panic.
Both std::time::Instant and tokio::time::Instant implement +/- that
panic when the result is out of range. This wrapper omits those operators
and exposes only checked_* arithmetic that returns None on overflow,
obliging the caller to handle the out-of-range case instead of risking a
panic. It wraps tokio::time::Instant to follow tokio’s test clock, and
converts to and from both the std and tokio instants at interop boundaries.
Implementations§
Source§impl Instant
impl Instant
Sourcepub fn checked_add(self, duration: Duration) -> Option<Self>
pub fn checked_add(self, duration: Duration) -> Option<Self>
Returns the instant duration after this one, or None if that would
overflow the underlying representation.
Sourcepub fn checked_sub(self, duration: Duration) -> Option<Self>
pub fn checked_sub(self, duration: Duration) -> Option<Self>
Returns the instant duration before this one, or None if that would
underflow the underlying representation.
Sourcepub fn checked_duration_since(self, earlier: Self) -> Option<Duration>
pub fn checked_duration_since(self, earlier: Self) -> Option<Duration>
Returns the duration elapsed from earlier to this instant, or None
if earlier is later than this instant.
Sourcepub fn saturating_duration_since(self, earlier: Self) -> Duration
pub fn saturating_duration_since(self, earlier: Self) -> Duration
Returns the duration elapsed from earlier to this instant, or a zero
duration if earlier is later than this instant.
Sourcepub fn checked_elapsed(self) -> Option<Duration>
pub fn checked_elapsed(self) -> Option<Duration>
Returns the duration elapsed since this instant, or None if this
instant is later than now.
Sourcepub fn saturating_elapsed(self) -> Duration
pub fn saturating_elapsed(self) -> Duration
Returns the duration elapsed since this instant, or a zero duration if this instant is later than now.
Sourcepub fn saturating_add(self, duration: Duration) -> Self
pub fn saturating_add(self, duration: Duration) -> Self
Returns the instant duration after this one, with duration clamped
to FAR_FUTURE. Use this where a very long duration means “never”,
such as a configured timeout or suspension.