Skip to main content

Clock

Trait Clock 

Source
pub trait Clock {
    // Required methods
    fn now() -> Self;
    fn set_scaling_factor(&mut self, scaling: usize);
    fn duration_since(&self, earlier: Self) -> Duration;
}
Expand description

A trait for time sources. This allows methods to be generic over different ways of measuring time.

Required Methods§

Source

fn now() -> Self

Get a timestamp.

Source

fn set_scaling_factor(&mut self, scaling: usize)

Set a scaling factor, which can be used to convert a difference of timestamps to seconds.

Source

fn duration_since(&self, earlier: Self) -> Duration

Get the duration from earlier to self as a std::time::Duration.

§Panics

If earlier is not earlier.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Clock for Instant

Source§

fn now() -> Self

Source§

fn set_scaling_factor(&mut self, _freq: usize)

Source§

fn duration_since(&self, earlier: Self) -> Duration

Implementors§