pub struct Instant { /* private fields */ }Expand description
A representation of an absolute time value.
The Instant type is a wrapper around a i64 value that
represents a number of microseconds, monotonically increasing
since an arbitrary moment in time, such as system startup.
- A value of
0is inherently arbitrary. - A value less than
0indicates a time before the starting point.
Implementations§
Source§impl Instant
impl Instant
Sourcepub const fn from_micros(micros: i64) -> Instant
pub const fn from_micros(micros: i64) -> Instant
Create a new Instant from a number of microseconds.
Sourcepub const fn from_millis(millis: i64) -> Instant
pub const fn from_millis(millis: i64) -> Instant
Create a new Instant from a number of milliseconds.
Sourcepub fn now() -> Instant
pub fn now() -> Instant
Create a new Instant from the current std::time::SystemTime.
Requires the std feature.
Sourcepub const fn as_secs(&self) -> i64
pub const fn as_secs(&self) -> i64
The number of whole seconds since the starting point.
Truncates towards zero for instants before the starting point.
Sourcepub const fn subsec_millis(&self) -> i64
pub const fn subsec_millis(&self) -> i64
The number of milliseconds past as_secs.
Always less than 1000 in absolute value.
Sourcepub const fn subsec_micros(&self) -> i64
pub const fn subsec_micros(&self) -> i64
The number of microseconds past as_secs.
Always less than 1000000 in absolute value.
Sourcepub const fn duration_since(&self, earlier: Instant) -> Duration
pub const fn duration_since(&self, earlier: Instant) -> Duration
The amount of time elapsed from earlier to this instant.
Returns Duration::ZERO if earlier is later than this instant.
Sourcepub const fn checked_duration_since(&self, earlier: Instant) -> Option<Duration>
pub const fn checked_duration_since(&self, earlier: Instant) -> Option<Duration>
The amount of time elapsed from earlier to this instant.
Returns None if earlier is later than this instant.
Sourcepub const fn saturating_duration_since(&self, earlier: Instant) -> Duration
pub const fn saturating_duration_since(&self, earlier: Instant) -> Duration
The amount of time elapsed from earlier to this instant.
Returns Duration::ZERO if earlier is later than this instant.
Sourcepub const fn checked_add(&self, duration: Duration) -> Option<Instant>
pub const fn checked_add(&self, duration: Duration) -> Option<Instant>
This instant plus duration, or None if the result does not fit.
Sourcepub const fn checked_sub(&self, duration: Duration) -> Option<Instant>
pub const fn checked_sub(&self, duration: Duration) -> Option<Instant>
This instant minus duration, or None if the result does not fit.
Sourcepub fn elapsed(&self) -> Duration
pub fn elapsed(&self) -> Duration
The amount of time elapsed since this instant.
Requires the std feature. Returns Duration::ZERO if this instant
is in the future.
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 moreimpl Copy for Instant
impl Eq for Instant
Source§impl From<Instant> for SystemTime
Available on crate feature std only.
impl From<Instant> for SystemTime
std only.Source§impl From<SystemTime> for Instant
Available on crate feature std only.
impl From<SystemTime> for Instant
std only.