Skip to main content

Clock

Trait Clock 

Source
pub trait Clock: Clone {
    type Instant: Reference;

    // Required methods
    fn now(&self) -> Self::Instant;
    fn sleep(&self, duration: Duration) -> impl Future<Output = ()> + Send + '_;
}
Expand description

A time source used by rate limiters.

Required Associated Types§

Source

type Instant: Reference

A measurement of a monotonically increasing clock.

Required Methods§

Source

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

Returns a measurement of the clock.

Source

fn sleep(&self, duration: Duration) -> impl Future<Output = ()> + Send + '_

Waits for duration on this clock’s time base.

Implementations must advance on the same clock as Clock::now so callers using sleep together with now observe consistent time under both real and simulated runtimes.

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.

Implementors§