pub struct Instant { /* private fields */ }Expand description
A point in time.
An Instant counts milliseconds from an arbitrary starting point, such as
system startup. It wraps around to zero every 232 ms, about 49.7
days. To make one from a wider timestamp, keep its low 32 bits.
Comparisons take the wraparound into account. Of two instants less than
231 ms (about 24.8 days) apart, the earlier one is the smaller one,
even if the counter wrapped around in between. Instants further apart than
that compare the wrong way around. This is why Instant implements
PartialOrd but not Ord.
The stack keeps every instant it holds close enough to the current time to
compare correctly, as long as Stack::poll is called
by the deadline it returns.
Implementations§
Source§impl Instant
impl Instant
Sourcepub const fn from_millis(millis: u32) -> Instant
pub const fn from_millis(millis: u32) -> Instant
Create a new Instant from a number of milliseconds.
Sourcepub const fn from_secs(secs: u32) -> Instant
pub const fn from_secs(secs: u32) -> Instant
Create a new Instant from a number of seconds.
Wraps around like the instant itself.
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_millis(&self) -> u32
pub const fn as_millis(&self) -> u32
The number of milliseconds since the starting point, wrapped around.
Sourcepub const fn subsec_millis(&self) -> u32
pub const fn subsec_millis(&self) -> u32
The number of milliseconds past as_secs.
Always less than 1000.
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.
Saturates at Duration::MAX.
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. Saturates at
Duration::MAX.
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.
Saturates at Duration::MAX.
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<SystemTime> for Instant
Available on crate feature std only.
impl From<SystemTime> for Instant
std only.Source§fn from(other: SystemTime) -> Instant
fn from(other: SystemTime) -> Instant
Counts from the unix epoch, and wraps around like any other Instant.