Trait TimeAbstraction

Source
pub trait TimeAbstraction {
    // Required methods
    fn now() -> Instant;
    async fn sleep_until(deadline: Instant) -> Result<(), Error>;
    fn interval(period: Duration) -> impl Interval;

    // Provided methods
    async fn sleep(duration: Duration) -> Result<(), Error> { ... }
    async fn timeout_at<F>(
        deadline: Instant,
        future: F,
    ) -> Result<<F as IntoFuture>::Output, Either<Exceeded, Error>>
       where Self: Sized,
             F: IntoFuture { ... }
}
Expand description

TimeAbstraction is used to perform time-related operations in a platform-agnostic manner.

Required Methods§

Source

fn now() -> Instant

Retrieves the current time.

Source

async fn sleep_until(deadline: Instant) -> Result<(), Error>

Returns a future that resolves successfully at the specified deadline (or earlier with an error).

Source

fn interval(period: Duration) -> impl Interval

Returns an Interval that will yield an item straight away and then once every period (unless there is an error).

If the stream consumer falls behind and multiple periods go by between reading from the stream, the stream will keep track of the missed periods and instantly yield them until caught up.

Provided Methods§

Source

async fn sleep(duration: Duration) -> Result<(), Error>

Returns a future that resolves successfully after the specified duration (or earlier with an error).

If the duration overflows Instant, the method sleeps for an unspecified time.

Source

async fn timeout_at<F>( deadline: Instant, future: F, ) -> Result<<F as IntoFuture>::Output, Either<Exceeded, Error>>
where Self: Sized, F: IntoFuture,

Returns a future that will resolve when: the wrapped future resolves, the deadline is reached, or there is an error.

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§

§

impl TimeAbstraction for veecle_os::osal::embassy::time::Time

Source§

impl TimeAbstraction for veecle_os::osal::freertos::time::Time

Source§

impl TimeAbstraction for veecle_os::osal::std::time::Time