pub struct Instant64<const TICKS_PER_SEC: u32> { /* private fields */ }Expand description
An Instant type using a single unsigned integer tick counter
For this type, it might be easy to create these instants and to handle the underlying
clock value, especially if the corresponding atomic type is available, see the
documentation to TimespecInstant.
The main drawback might be that all additions and subtractions require divisions which might be inefficient on some platforms (when using an integer type larger than the word width of the processor):
- Subtracting two instants yields a
Durationwhich is a struct of seconds and (subsecond) nanoseconds. So this requires division and modulo to convert the simple tick difference into aDuration. - Adding/subtracting a
Durationto/from an instant requires to convert the seconds and nanoseconds into the corresponding ticks. Converting the seconds only requires multiplication withTICKS_PER_SEC, but converting the nanoseconds requires division bynanos_per_sec(which is calculated internally). This division is only a 32 bit division though.
This instant type is generic on the clock frequency TICKS_PER_SEC. For example, in
order to implement a millisecond clock, set TICKS_PER_SEC to 1000.
Implementations§
Trait Implementations§
Source§impl<const TICKS_PER_SEC: u32> Add<Duration> for Instant64<TICKS_PER_SEC>
impl<const TICKS_PER_SEC: u32> Add<Duration> for Instant64<TICKS_PER_SEC>
Source§impl<const TICKS_PER_SEC: u32> AddAssign<Duration> for Instant64<TICKS_PER_SEC>
impl<const TICKS_PER_SEC: u32> AddAssign<Duration> for Instant64<TICKS_PER_SEC>
Source§fn add_assign(&mut self, other: Duration)
fn add_assign(&mut self, other: Duration)
Performs the
+= operation. Read moreSource§impl<const TICKS_PER_SEC: u32> Instant for Instant64<TICKS_PER_SEC>
impl<const TICKS_PER_SEC: u32> Instant for Instant64<TICKS_PER_SEC>
Source§fn checked_duration_since(&self, earlier: Self) -> Option<Duration>
fn checked_duration_since(&self, earlier: Self) -> Option<Duration>
Returns the amount of time elapsed from another instant to this one, or None if that
instant is later than this one. Read more
Source§fn checked_add(&self, duration: Duration) -> Option<Self>
fn checked_add(&self, duration: Duration) -> Option<Self>
Returns
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>
Returns
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
Returns the amount of time elapsed from another instant to this one, or zero duration if
that instant is later than this one. Read more
Source§fn saturating_duration_since(&self, earlier: Self) -> Duration
fn saturating_duration_since(&self, earlier: Self) -> Duration
Returns the amount of time elapsed from another instant to this one, or zero duration if
that instant is later than this one. Read more
Source§impl<const TICKS_PER_SEC: u32> Ord for Instant64<TICKS_PER_SEC>
impl<const TICKS_PER_SEC: u32> Ord for Instant64<TICKS_PER_SEC>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<const TICKS_PER_SEC: u32> PartialOrd for Instant64<TICKS_PER_SEC>
impl<const TICKS_PER_SEC: u32> PartialOrd for Instant64<TICKS_PER_SEC>
Source§impl<const TICKS_PER_SEC: u32> Sub for Instant64<TICKS_PER_SEC>
impl<const TICKS_PER_SEC: u32> Sub for Instant64<TICKS_PER_SEC>
Source§impl<const TICKS_PER_SEC: u32> SubAssign<Duration> for Instant64<TICKS_PER_SEC>
impl<const TICKS_PER_SEC: u32> SubAssign<Duration> for Instant64<TICKS_PER_SEC>
Source§fn sub_assign(&mut self, other: Duration)
fn sub_assign(&mut self, other: Duration)
Performs the
-= operation. Read moreimpl<const TICKS_PER_SEC: u32> Copy for Instant64<TICKS_PER_SEC>
impl<const TICKS_PER_SEC: u32> Eq for Instant64<TICKS_PER_SEC>
impl<const TICKS_PER_SEC: u32> StructuralPartialEq for Instant64<TICKS_PER_SEC>
Auto Trait Implementations§
impl<const TICKS_PER_SEC: u32> Freeze for Instant64<TICKS_PER_SEC>
impl<const TICKS_PER_SEC: u32> RefUnwindSafe for Instant64<TICKS_PER_SEC>
impl<const TICKS_PER_SEC: u32> Send for Instant64<TICKS_PER_SEC>
impl<const TICKS_PER_SEC: u32> Sync for Instant64<TICKS_PER_SEC>
impl<const TICKS_PER_SEC: u32> Unpin for Instant64<TICKS_PER_SEC>
impl<const TICKS_PER_SEC: u32> UnwindSafe for Instant64<TICKS_PER_SEC>
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
Mutably borrows from an owned value. Read more