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§
Sourcefn sleep(&self, duration: Duration) -> impl Future<Output = ()> + Send + Sync
fn sleep(&self, duration: Duration) -> impl Future<Output = ()> + Send + Sync
Initiates a sleep for the specified duration
Sourcefn non_advancing_sleep(
&self,
duration: Duration,
) -> impl Future<Output = ()> + Send + Sync
fn non_advancing_sleep( &self, duration: Duration, ) -> impl Future<Output = ()> + Send + Sync
Initiates a sleep for the specified duration
Sourcefn sleep_until(
&self,
deadline: Instant,
) -> impl Future<Output = ()> + Send + Sync
fn sleep_until( &self, deadline: Instant, ) -> impl Future<Output = ()> + Send + Sync
Sleep until the specified deadline.
Sourcefn system_time_now(&self) -> SystemTime
fn system_time_now(&self) -> SystemTime
Get the current system time according to the clock
Sourcefn timeout<F, T>(
&self,
duration: Duration,
f: F,
) -> impl Future<Output = Result<T, TimeoutError>> + Send
fn timeout<F, T>( &self, duration: Duration, f: F, ) -> impl Future<Output = Result<T, TimeoutError>> + 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.