pub trait MonotonicClock {
// Required methods
fn epoch(&self) -> Epoch;
fn now(&self) -> Duration;
fn is_ticking(&self) -> bool;
// Provided methods
fn time(&self) -> Duration { ... }
fn time_as_float(&self) -> f64 { ... }
fn as_float(&self) -> f64 { ... }
}Expand description
§Monotonic Clock
A monotonic clock that can be anchored to a specific Epoch. The clock is guaranteed to be monotonic, but not necessarily continuous.
§Thread safety
The clock is thread safe.
Eventually, we want to have network synchronization, but for now, we just use the system clock. TODO: Add network synchronization.
§Example
use monotonic_clock::Clock;
use std::thread;
use std::time::Duration;
let clock = Clock::new();
let start = clock.now();
thread::sleep(Duration::from_millis(100));
let end = clock.now();
assert!(end - start >= Duration::from_millis(100));Required Methods§
Sourcefn is_ticking(&self) -> bool
fn is_ticking(&self) -> bool
Returns true if the clock is ticking.
Provided Methods§
Sourcefn time_as_float(&self) -> f64
fn time_as_float(&self) -> f64
Get the now time since the epoch as a float.