Trait Clock

Source
pub trait Clock {
    // Required methods
    fn sleep(
        &self,
        duration: Duration,
    ) -> impl Future<Output = ()> + Send + Sync;
    fn non_advancing_sleep(
        &self,
        duration: Duration,
    ) -> impl Future<Output = ()> + Send + Sync;
    fn now(&self) -> Instant;
    fn sleep_until(
        &self,
        deadline: Instant,
    ) -> impl Future<Output = ()> + Send + Sync;
    fn system_time_now(&self) -> SystemTime;
    fn timeout<F, T>(
        &self,
        duration: Duration,
        f: F,
    ) -> impl Future<Output = Result<T, TimeoutError>> + Send
       where F: Future<Output = T> + Send;
}
Expand description

The Sleeps trait allows different implementations to control the behavior of sleep.

Required Methods§

Source

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

Initiates a sleep for the specified duration

Source

fn non_advancing_sleep( &self, duration: Duration, ) -> impl Future<Output = ()> + Send + Sync

Initiates a sleep for the specified duration

Source

fn now(&self) -> Instant

Get the current time according to the clock

Source

fn sleep_until( &self, deadline: Instant, ) -> impl Future<Output = ()> + Send + Sync

Sleep until the specified deadline.

Source

fn system_time_now(&self) -> SystemTime

Get the current system time according to the clock

Source

fn timeout<F, T>( &self, duration: Duration, f: F, ) -> impl Future<Output = Result<T, TimeoutError>> + Send
where F: Future<Output = T> + Send,

Require a future to complete within the specified duration

if the future completes before the duration has elapsed, then the completed value is returned. Otherwise, an error is returned and the future is canceled.

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§