MonotonicClock

Trait MonotonicClock 

Source
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§

Source

fn epoch(&self) -> Epoch

Return the epoch of the clock.

Source

fn now(&self) -> Duration

Returns the current time.

Source

fn is_ticking(&self) -> bool

Returns true if the clock is ticking.

Provided Methods§

Source

fn time(&self) -> Duration

Get the now time since the epoch.

Source

fn time_as_float(&self) -> f64

Get the now time since the epoch as a float.

Source

fn as_float(&self) -> f64

Get the now time since the epoch as a float. This is a convenience function for clock_as_float. It is provided for compatibility with the time crate.

Implementors§