Struct tor_rtcompat::CoarseInstant
source · pub struct CoarseInstant(/* private fields */);
Expand description
A monotonic timestamp with reduced precision, and, in the future, saturating arithmetic
Like std::time::Instant
, but:
-
RealCoarseTimeProvider::now_coarse()
is cheap on all platforms, unlikestd::time::Instant::now
. -
Not true yet: Arithmetic is saturating (so, it’s panic-free).
-
Precision and accuracy are reduced.
-
Cannot be compared with, or converted to/from,
std::time::Instant
. It has a completely different timescale toInstant
.
You can obtain this (only) from CoarseTimeProvider::now_coarse
.
§Range and precision
The range of a CoarseInstant
is not directly visible,
since the absolute value isn’t.
CoarseInstant
s are valid only within the context of one program execution (process).
Correct behaviour with processes that run for more than 2^31 seconds (about 30 years) is not guaranteed.
The precision is no worse than 1 second.
§Panics
Currently, operations on CoarseInstant
and CoarseDuration
can panic on under/overflow.
We regard this as a bug.
The intent is that all operations will saturate.
Trait Implementations§
source§impl Add<CoarseDuration> for CoarseInstant
impl Add<CoarseDuration> for CoarseInstant
§type Output = CoarseInstant
type Output = CoarseInstant
+
operator.source§fn add(self, rhs: CoarseDuration) -> CoarseInstant
fn add(self, rhs: CoarseDuration) -> CoarseInstant
+
operation. Read moresource§impl AddAssign<CoarseDuration> for CoarseInstant
impl AddAssign<CoarseDuration> for CoarseInstant
source§fn add_assign(&mut self, rhs: CoarseDuration)
fn add_assign(&mut self, rhs: CoarseDuration)
+=
operation. Read moresource§impl Clone for CoarseInstant
impl Clone for CoarseInstant
source§fn clone(&self) -> CoarseInstant
fn clone(&self) -> CoarseInstant
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for CoarseInstant
impl Debug for CoarseInstant
source§impl Hash for CoarseInstant
impl Hash for CoarseInstant
source§impl Ord for CoarseInstant
impl Ord for CoarseInstant
source§fn cmp(&self, other: &CoarseInstant) -> Ordering
fn cmp(&self, other: &CoarseInstant) -> 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 CoarseInstant
impl PartialEq for CoarseInstant
source§fn eq(&self, other: &CoarseInstant) -> bool
fn eq(&self, other: &CoarseInstant) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for CoarseInstant
impl PartialOrd for CoarseInstant
source§fn partial_cmp(&self, other: &CoarseInstant) -> Option<Ordering>
fn partial_cmp(&self, other: &CoarseInstant) -> Option<Ordering>
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 Sub<CoarseDuration> for CoarseInstant
impl Sub<CoarseDuration> for CoarseInstant
§type Output = CoarseInstant
type Output = CoarseInstant
-
operator.source§fn sub(self, rhs: CoarseDuration) -> CoarseInstant
fn sub(self, rhs: CoarseDuration) -> CoarseInstant
-
operation. Read moresource§impl SubAssign<CoarseDuration> for CoarseInstant
impl SubAssign<CoarseDuration> for CoarseInstant
source§fn sub_assign(&mut self, rhs: CoarseDuration)
fn sub_assign(&mut self, rhs: CoarseDuration)
-=
operation. Read more