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".