pub struct TimespecInstant { /* private fields */ }Expand description
An Instant type inspired by the timespec struct from the C standard library
This instant type is implemented in a similar way as the Duration type because they both
use a struct of seconds and (subsecond) nanoseconds to represent time. This has the great
benefit that additions and subtractions do not require divisions, see the documentation to
Instant32 and Instant64.
The main drawback of this instant type might be that creating these instants is harder. It can be done in basically two ways:
- The underlying clock uses a simple integer tick counter. In these cases, creating each
instant requires the division which is saved when working with the instants. Depending on
the use case, this might be more or less efficient than using
Instant32orInstant64. - The underlying clock works on a similar seconds+nanoseconds struct directly. In these cases,
creating an instant is easy but incrementing the underlying value in the clock tick
interrupt gets harder. It is harder because the clock tick interrupt handler needs to take
care of the nanosecond overflow which happens once per second and which needs to be properly
synchronized with the contexts which request instants. Note though, that this might be the
same problem as implementing a clock for
Instant32orInstant64on platforms that do not support the corresponding atomic types. Especially on widespread 32 bit platforms, theAtomicU64might be missing.
Also, if you are especially concerned about data sizes, Instant32 might be more appropriate
for you because this type uses a 64 bit representation, see below.
The seconds and nanoseconds are both stored as u32 values. For the nanoseconds, this should
be obvious. For the seconds, using a 32 bit integer might remind of the year 2038 problem but this is only relevant when
working with wall clock times. Since Instant is about working with monotonic clocks which can
always be measured since program or system start, this would only be relevant if the program or
system was designed to run for longer than about 136 years. So this should affect nearly no
users at all. Therefore, saving additional bits seems reasonable.
Implementations§
Trait Implementations§
Source§impl Add<Duration> for TimespecInstant
impl Add<Duration> for TimespecInstant
Source§fn add(self, other: Duration) -> TimespecInstant
fn add(self, other: Duration) -> TimespecInstant
§Panics
This function may panic if the resulting point in time cannot be represented by the
underlying data structure. See Instant::checked_add for a version without panic.
Source§type Output = TimespecInstant
type Output = TimespecInstant
+ operator.Source§impl AddAssign<Duration> for TimespecInstant
impl AddAssign<Duration> for TimespecInstant
Source§fn add_assign(&mut self, other: Duration)
fn add_assign(&mut self, other: Duration)
+= operation. Read moreSource§impl Clone for TimespecInstant
impl Clone for TimespecInstant
Source§fn clone(&self) -> TimespecInstant
fn clone(&self) -> TimespecInstant
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TimespecInstant
impl Debug for TimespecInstant
Source§impl Hash for TimespecInstant
impl Hash for TimespecInstant
Source§impl Instant for TimespecInstant
impl Instant for TimespecInstant
Source§fn checked_duration_since(&self, earlier: Self) -> Option<Duration>
fn checked_duration_since(&self, earlier: Self) -> Option<Duration>
Source§fn checked_add(&self, duration: Duration) -> Option<Self>
fn checked_add(&self, duration: Duration) -> Option<Self>
Some(t) where t is the time self + duration if t can be represented as
Self (which means it’s inside the bounds of the underlying data structure), None
otherwise.Source§fn checked_sub(&self, duration: Duration) -> Option<Self>
fn checked_sub(&self, duration: Duration) -> Option<Self>
Some(t) where t is the time self - duration if t can be represented as
Instant (which means it’s inside the bounds of the underlying data structure), None
otherwise.Source§fn duration_since(&self, earlier: Self) -> Duration
fn duration_since(&self, earlier: Self) -> Duration
Source§fn saturating_duration_since(&self, earlier: Self) -> Duration
fn saturating_duration_since(&self, earlier: Self) -> Duration
Source§impl Ord for TimespecInstant
impl Ord for TimespecInstant
Source§fn cmp(&self, other: &TimespecInstant) -> Ordering
fn cmp(&self, other: &TimespecInstant) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for TimespecInstant
impl PartialEq for TimespecInstant
Source§impl PartialOrd for TimespecInstant
impl PartialOrd for TimespecInstant
Source§impl Sub<Duration> for TimespecInstant
impl Sub<Duration> for TimespecInstant
Source§type Output = TimespecInstant
type Output = TimespecInstant
- operator.Source§impl Sub for TimespecInstant
impl Sub for TimespecInstant
Source§impl SubAssign<Duration> for TimespecInstant
impl SubAssign<Duration> for TimespecInstant
Source§fn sub_assign(&mut self, other: Duration)
fn sub_assign(&mut self, other: Duration)
-= operation. Read more