pub struct Timestamp(/* private fields */);Expand description
An absolute point in time.
The absolute value of Timestamps should be treated as opaque. It is not
necessarily related to any calendar time.
Timestamps should only be compared if they are are sourced from the same
clock.
Timestamps are similar to the Instant data-type in the Rust standard
library, but can be created even without an available standard library.
The size of Timestamp is guaranteed to be consistent across platforms.
Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub fn checked_add(self, duration: Duration) -> Option<Self>
pub fn checked_add(self, duration: Duration) -> Option<Self>
Tries to calculate a Timestamp based on the current Timestamp and
adding the provided Duration. If this Timestamp is representable
within the range of Timestamp it is returned as Some(timestamp).
Otherwise None is returned.
Sourcepub fn checked_sub(self, duration: Duration) -> Option<Self>
pub fn checked_sub(self, duration: Duration) -> Option<Self>
Tries to calculate a Timestamp based on the current Timestamp and
subtracting the provided Duration. If this Timestamp is representable
within the range of Timestamp it is returned as Some(timestamp).
Otherwise None is returned.
Sourcepub fn saturating_duration_since(self, earlier: Self) -> Duration
pub fn saturating_duration_since(self, earlier: Self) -> Duration
Returns the Duration which elapsed since an earlier Timestamp.
If earlier is more recent, the method returns a Duration of 0.
Sourcepub unsafe fn from_duration(duration: Duration) -> Self
pub unsafe fn from_duration(duration: Duration) -> Self
Creates a Timestamp from a Duration since the time source’s epoch.
This will treat the duration as an absolute point in time.
§Safety
This should only be used by time sources
Sourcepub unsafe fn as_duration(self) -> Duration
pub unsafe fn as_duration(self) -> Duration
Converts the Timestamp into the Duration since the time source’s epoch.
§Safety
This should only be used by time sources
Sourcepub const fn has_elapsed(self, now: Self) -> bool
pub const fn has_elapsed(self, now: Self) -> bool
Compares the timestamp to the current time and returns true if it is in the past
Note that this compares milliseconds, as any finer resolution would result in excessive timer churn.
Trait Implementations§
Source§impl AddAssign<Duration> for Timestamp
impl AddAssign<Duration> for Timestamp
Source§fn add_assign(&mut self, other: Duration)
fn add_assign(&mut self, other: Duration)
+= operation. Read moreSource§impl Ord for Timestamp
impl Ord for Timestamp
Source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
Source§impl SubAssign<Duration> for Timestamp
impl SubAssign<Duration> for Timestamp
Source§fn sub_assign(&mut self, other: Duration)
fn sub_assign(&mut self, other: Duration)
-= operation. Read more