Struct Instant
pub struct Instant(/* private fields */);Expand description
A point on the monotonic clock, in nanoseconds from the clock’s origin.
The methods mirror std::time::Instant’s, except that moving one by a Duration
has no operator: each caller picks checked_ or saturating_, so a duration past the
clock’s range is handled rather than panicking. The time between two instants
(duration_since and -) saturates to zero when the later one
comes first, as std’s does; checked_duration_since
reports that case instead. Instants are only comparable within one clock: the simulator
starts at Instant::ZERO, and the runtime backends count from an origin they
pick once, reading far past zero there so earlier moments stay representable.
Instant::into_std and Instant::from_std convert at a third-party API that takes
std’s instants.
Implementations§
§impl Instant
impl Instant
pub fn elapsed(&self) -> Duration
pub fn elapsed(&self) -> Duration
The time elapsed since this instant on the ambient clock, zero if it is in the future.
pub fn duration_since(&self, earlier: Instant) -> Duration
pub fn duration_since(&self, earlier: Instant) -> Duration
The time from earlier to this instant, zero if earlier is later.
pub fn checked_duration_since(&self, earlier: Instant) -> Option<Duration>
pub fn checked_duration_since(&self, earlier: Instant) -> Option<Duration>
The time from earlier to this instant, or None if earlier is later.
pub fn saturating_duration_since(&self, earlier: Instant) -> Duration
pub fn saturating_duration_since(&self, earlier: Instant) -> Duration
The time from earlier to this instant, zero if earlier is later.
pub fn checked_add(&self, duration: Duration) -> Option<Instant>
pub fn checked_add(&self, duration: Duration) -> Option<Instant>
This instant moved forward by duration, or None past the clock’s range.
pub fn checked_sub(&self, duration: Duration) -> Option<Instant>
pub fn checked_sub(&self, duration: Duration) -> Option<Instant>
This instant moved back by duration, or None before the clock’s origin.
pub fn saturating_add(&self, duration: Duration) -> Instant
pub fn saturating_add(&self, duration: Duration) -> Instant
This instant moved forward by duration, stopping at the clock’s last instant.
pub fn saturating_sub(&self, duration: Duration) -> Instant
pub fn saturating_sub(&self, duration: Duration) -> Instant
This instant moved back by duration, stopping at the clock’s origin.
pub fn into_std(self) -> Instant
pub fn into_std(self) -> Instant
This instant on std’s clock, for a third-party API that takes one.
Maps through the runtime backend’s origin, as its timers do. That is exact on
a running clock. On paused tokio or the simulator it keeps the time between
instants, but not their distance from std::time::Instant::now.
§Panics
When std’s clock cannot represent it, as with a simulated instant near zero on a platform whose std clock starts at boot.
pub fn from_std(at: Instant) -> Instant
pub fn from_std(at: Instant) -> Instant
The instant at names on std’s clock, the inverse of Instant::into_std.
Saturates at the clock’s range, like a deadline past it.
Trait Implementations§
impl Copy for Instant
impl Eq for Instant
§impl Ord for Instant
impl Ord for Instant
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
§impl PartialOrd for Instant
impl PartialOrd for Instant
impl StructuralPartialEq for Instant
Auto Trait Implementations§
impl Freeze for Instant
impl RefUnwindSafe for Instant
impl Send for Instant
impl Sync for Instant
impl Unpin for Instant
impl UnsafeUnpin for Instant
impl UnwindSafe for Instant
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.