Struct s2n_quic_core::time::Timestamp
source · pub struct Timestamp(/* private fields */);
Expand description
An absolute point in time.
The absolute value of Timestamp
s should be treated as opaque. It is not
necessarily related to any calendar time.
Timestamp
s should only be compared if they are are sourced from the same
clock.
Timestamp
s 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 PartialEq for Timestamp
impl PartialEq for Timestamp
source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§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