Skip to main content

TimerHal

Trait TimerHal 

Source
pub trait TimerHal {
    // Required methods
    fn now_micros(&self) -> u64;
    fn delay(&self, millis: u64) -> impl Future<Output = ()>;

    // Provided method
    fn now_millis(&self) -> u64 { ... }
}
Expand description

Timer hardware abstraction.

Provides time measurement and delays. Implementations typically wrap system tick timers or RTOS timer facilities.

§Example

ⓘ
async fn measure_time<T: TimerHal>(timer: &T) -> u64 {
    let start = timer.now_millis();
    some_operation().await;
    timer.now_millis() - start
}

Required Methods§

Source

fn now_micros(&self) -> u64

Get current time in microseconds since boot.

Returns a monotonically increasing counter of microseconds since system startup. May wrap around on long-running systems.

Source

fn delay(&self, millis: u64) -> impl Future<Output = ()>

Wait for specified duration.

Asynchronously waits for the specified number of milliseconds. This is an async operation that yields to the executor.

§Arguments
  • millis - Duration to wait in milliseconds.

Provided Methods§

Source

fn now_millis(&self) -> u64

Get current time in milliseconds since boot.

Convenience wrapper around Self::now_micros with millisecond resolution.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§