pub struct Monotonic(/* private fields */);std only.Expand description
A captured monotonic instant.
Monotonic wraps a single sample of the operating system’s monotonic
clock. Two readings can be compared to recover the Duration between
them with duration_since or the safer
checked_duration_since.
Monotonic and Wall are deliberately distinct types
with no cross-type arithmetic. The compiler will reject any attempt to
mix them — that separation is the central design choice of this crate.
Construct one with Monotonic::now or the crate-level
now shortcut.
§Examples
use clock_lib::Monotonic;
let start = Monotonic::now();
// ... do some work ...
let took = start.elapsed();
assert!(took.as_nanos() < u128::MAX);Implementations§
Source§impl Monotonic
impl Monotonic
Sourcepub fn duration_since(self, earlier: Self) -> Duration
pub fn duration_since(self, earlier: Self) -> Duration
Returns the Duration between two readings.
§Panics
Panics if earlier is later than self. Prefer
checked_duration_since or
saturating_duration_since
when the ordering is not guaranteed by construction.
§Examples
use clock_lib::Monotonic;
let earlier = Monotonic::now();
let later = Monotonic::now();
let _delta = later.duration_since(earlier);Sourcepub fn checked_duration_since(self, earlier: Self) -> Option<Duration>
pub fn checked_duration_since(self, earlier: Self) -> Option<Duration>
Returns Some(duration) if self >= earlier, otherwise None.
The non-panicking counterpart to
duration_since.
§Examples
use clock_lib::Monotonic;
let earlier = Monotonic::now();
let later = Monotonic::now();
assert!(later.checked_duration_since(earlier).is_some());Sourcepub fn saturating_duration_since(self, earlier: Self) -> Duration
pub fn saturating_duration_since(self, earlier: Self) -> Duration
Returns the duration since earlier, saturating at zero when
earlier is later than self.
§Examples
use clock_lib::Monotonic;
let a = Monotonic::now();
let b = Monotonic::now();
// Regardless of which is later, this never panics.
let _ = a.saturating_duration_since(b);