Skip to main content

Timer

Trait Timer 

Source
pub trait Timer {
    // Required methods
    fn now(&self) -> Instant;
    fn sleep_until(&self, deadline: Instant) -> impl Future<Output = ()>;

    // Provided method
    fn sleep(&self, duration: Duration) -> impl Future<Output = ()> { ... }
}
Expand description

Monotonic time, and the ability to wait for it.

“Monotonic” is the whole requirement: it must never go backwards, and it must not jump when somebody sets the wall clock. Matter’s deadlines are all durations from now.

Required Methods§

Source

fn now(&self) -> Instant

How long since some fixed point this timer never changes.

Source

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

Completes at deadline, or immediately if it has passed.

Provided Methods§

Source

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

Completes after duration.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Timer for SimNet

Source§

impl Timer for StdTimer

Available on crate feature std only.