Trait Clock

Source
pub trait Clock {
    type Instant: Copy;
    type Duration: Copy;

    // Required methods
    fn now(&self) -> Self::Instant;
    fn elapsed_since(&self, instant: Self::Instant) -> Self::Duration;
    fn has_elapsed(
        &self,
        instant: Self::Instant,
        duration: &Self::Duration,
    ) -> bool;
    fn duration_from_millis(&self, millis: u64) -> Self::Duration;
}
Expand description

A trait for time-keeping implementations.

Required Associated Types§

Source

type Instant: Copy

A type representing a specific instant in time.

Source

type Duration: Copy

A type representing a duration of time

Required Methods§

Source

fn now(&self) -> Self::Instant

Get the current time.

Source

fn elapsed_since(&self, instant: Self::Instant) -> Self::Duration

Calculate the duration elapsed since the given instant.

Source

fn has_elapsed(&self, instant: Self::Instant, duration: &Self::Duration) -> bool

Check if a duration has passed since the given instant.

Source

fn duration_from_millis(&self, millis: u64) -> Self::Duration

Create a duration from milliseconds.

Implementors§