pub trait Clock {
type Reading: Copy;
// Required method
fn now(&self) -> Self::Reading;
}Expand description
A clock: what time it is now.
The type a clock reads says which timeline its readings are on, so readings of two timelines never mix: a point for a clock that names a moment, and a span for one that counts CPU time.
§Examples
use core::cell::Cell;
use t2t_clock::Clock;
use t2t_core::Tickstamp;
/// A clock that moves one tick at each reading.
struct StepClock(Cell<i64>);
impl Clock for StepClock {
type Reading = Tickstamp;
fn now(&self) -> Tickstamp {
self.0.set(self.0.get() + 1);
Tickstamp::from_ticks(self.0.get())
}
}
let clock = StepClock(Cell::new(0));
assert!(clock.now() < clock.now(), "each reading later than the last");Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Implementors§
Source§impl Clock for BootClock
Available on 64-bit and crate feature std and (Linux or macOS) only.
impl Clock for BootClock
Available on 64-bit and crate feature
std and (Linux or macOS) only.type Reading = BootUptime
Source§impl Clock for CoarseMonotonicClock
Available on 64-bit and crate feature std and (Linux or macOS) only.
impl Clock for CoarseMonotonicClock
Available on 64-bit and crate feature
std and (Linux or macOS) only.Source§impl Clock for CoarseSystemClock
Available on 64-bit and crate feature std and (Linux or macOS) only.
impl Clock for CoarseSystemClock
Available on 64-bit and crate feature
std and (Linux or macOS) only.Source§impl Clock for MonotonicClock
Available on 64-bit and crate feature std and (Linux or macOS) only.
impl Clock for MonotonicClock
Available on 64-bit and crate feature
std and (Linux or macOS) only.Source§impl Clock for ProcessCpuClock
Available on 64-bit and crate feature std and (Linux or macOS) only.
impl Clock for ProcessCpuClock
Available on 64-bit and crate feature
std and (Linux or macOS) only.Source§impl Clock for RawMonotonicClock
Available on 64-bit and crate feature std and (Linux or macOS) only.
impl Clock for RawMonotonicClock
Available on 64-bit and crate feature
std and (Linux or macOS) only.Source§impl Clock for SystemClock
Available on 64-bit and crate feature std and (Linux or macOS) only.
impl Clock for SystemClock
Available on 64-bit and crate feature
std and (Linux or macOS) only.Source§impl Clock for TaiClock
Available on 64-bit and crate feature std and (Linux or macOS) only.
impl Clock for TaiClock
Available on 64-bit and crate feature
std and (Linux or macOS) only.type Reading = TaiTimestamp
Source§impl Clock for ThreadCpuClock
Available on 64-bit and crate feature std and (Linux or macOS) only.
impl Clock for ThreadCpuClock
Available on 64-bit and crate feature
std and (Linux or macOS) only.