pub struct Instant(/* private fields */);
Expand description
A measurement of a monotonically increasing clock.
Opaque and useful only with Duration
.
Resulting durations are actual durations; they do not get affected by
clock adjustments, leap seconds, or similar.
In order to get a measurement of the wall clock, use Date
instead.
Implementations§
Source§impl Instant
impl Instant
Sourcepub fn now() -> Instant
pub fn now() -> Instant
Returns an instant corresponding to “now”
This function also updates the stored instant.
Sourcepub fn now_without_cache_update() -> Instant
pub fn now_without_cache_update() -> Instant
Returns an instant corresponding to “now” without updating the cached value.
After this, recent()
will still return the old instant.
now()
is generally preferred over this function.
Sourcepub fn update()
pub fn update()
Update the stored instant
This function should be called frequently, for example in an event loop
or using an Updater
task.
Sourcepub fn duration_since(&self, earlier: Instant) -> Duration
pub fn duration_since(&self, earlier: Instant) -> Duration
Returns the amount of time elapsed from another instant to this one
Sourcepub fn elapsed_since_recent(&self) -> Duration
pub fn elapsed_since_recent(&self) -> Duration
Returns the amount of time elapsed between the this instant was created and the latest update
Sourcepub fn elapsed(&self) -> Duration
pub fn elapsed(&self) -> Duration
Returns the amount of time elapsed since this instant was created
This function also updates the stored instant.
Sourcepub fn as_ticks(&self) -> u64
pub fn as_ticks(&self) -> u64
Return a representation of this instant as a number of “ticks”.
Note that length of a ‘tick’ is not guaranteed to represent
the same amount of time across different platforms, or from
one version of coarsetime
to another.
Note also that the instant represented by “0” ticks is
unspecified. It is not guaranteed to be the same time across
different platforms, or from one version of coarsetime
to
another.
This API is mainly intended for applications that need to
store the value of an Instant
in an
AtomicU64
.
Sourcepub fn saturating_add(self, rhs: Duration) -> Instant
pub fn saturating_add(self, rhs: Duration) -> Instant
Calculate an Instant
that is a Duration
later, saturating on overflow
Sourcepub fn checked_add(self, rhs: Duration) -> Option<Instant>
pub fn checked_add(self, rhs: Duration) -> Option<Instant>
Calculate an Instant
that is a Duration
later, returning None
on overflow
Sourcepub fn saturating_sub(self, rhs: Duration) -> Instant
pub fn saturating_sub(self, rhs: Duration) -> Instant
Calculate an Instant
that is a Duration
earlier, saturating on underflow
Sourcepub fn checked_sub(self, rhs: Duration) -> Option<Instant>
pub fn checked_sub(self, rhs: Duration) -> Option<Instant>
Calculate an Instant
that is a Duration
earlier, returning None
on underflow
Trait Implementations§
Source§impl AddAssign<Duration> for Instant
impl AddAssign<Duration> for Instant
Source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+=
operation. Read moreSource§impl Ord for Instant
impl Ord for Instant
Source§impl PartialOrd for Instant
impl PartialOrd for Instant
Source§impl SubAssign<Duration> for Instant
impl SubAssign<Duration> for Instant
Source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
-=
operation. Read more