Skip to main content

Timer

Trait Timer 

Source
pub trait Timer {
    // Required methods
    fn start(&mut self);
    fn tickrate(&self) -> u64;
    fn elapsed_ticks(&self) -> Result<u64, OverflowError>;
    fn elapsed_nanos(&self) -> Result<u64, OverflowError>;
    fn elapsed_micros(&self) -> Result<u64, OverflowError>;
    fn elapsed_millis(&self) -> Result<u64, OverflowError>;
    fn elapsed_secs(&self) -> Result<u64, OverflowError>;
    fn max_ticks(&self) -> u64;
    fn max_nanos(&self) -> u64;
    fn max_micros(&self) -> u64;
    fn max_millis(&self) -> u64;
    fn max_secs(&self) -> u64;
}
Expand description

A timer that can be started from 0 and keeps track of the time until it overflows.

This trait may be implemented directly on top of short running hardware timers or on top of ‘virtual’ long running timers.

A driver using this trait should document the minimum required tick resolution and the minimum required max time. The driver may choose to check if these invariants are kept using the tickrate and the various max_* functions.

Required Methods§

Source

fn start(&mut self)

Start or restart the timer at 0.

The elapsed time is undefined before this function has been called.

Source

fn tickrate(&self) -> u64

Get the amount of ticks per second.

This value should remain constant unless explicitly changed by the user of this trait out-of-band.

Source

fn elapsed_ticks(&self) -> Result<u64, OverflowError>

Return the number of elapsed ticks.

Source

fn elapsed_nanos(&self) -> Result<u64, OverflowError>

Return the number of elapsed nanoseconds, rounded down.

Source

fn elapsed_micros(&self) -> Result<u64, OverflowError>

Return the number of elapsed microseconds, rounded down.

Source

fn elapsed_millis(&self) -> Result<u64, OverflowError>

Return the number of elapsed milliseconds, rounded down.

Source

fn elapsed_secs(&self) -> Result<u64, OverflowError>

Return the number of elapsed seconds, rounded down.

Source

fn max_ticks(&self) -> u64

The (inclusive) maximum number of ticks that can elapse after start before the timer overflows.

This value must remain constant unless the user made an explicit out-of-band change to the timer.

When the timer is designed to (practically) never overflow, a value of u64::MAX may be used even when the implementation doesn’t have a constant max value.

Source

fn max_nanos(&self) -> u64

The (inclusive) maximum number of nanoseconds that can elapse after start before the timer overflows.

This value must remain constant unless the user made an explicit out-of-band change to the timer.

When the timer is designed to (practically) never overflow, a value of u64::MAX may be used even when the implementation doesn’t have a constant max value.

Source

fn max_micros(&self) -> u64

The (inclusive) maximum number of microseconds that can elapse after start before the timer overflows.

This value must remain constant unless the user made an explicit out-of-band change to the timer.

When the timer is designed to (practically) never overflow, a value of u64::MAX may be used even when the implementation doesn’t have a constant max value.

Source

fn max_millis(&self) -> u64

The (inclusive) maximum number of milliseconds that can elapse after start before the timer overflows.

This value must remain constant unless the user made an explicit out-of-band change to the timer.

When the timer is designed to (practically) never overflow, a value of u64::MAX may be used even when the implementation doesn’t have a constant max value.

Source

fn max_secs(&self) -> u64

The (inclusive) maximum number of seconds that can elapse after start before the timer overflows.

This value must remain constant unless the user made an explicit out-of-band change to the timer.

When the timer is designed to (practically) never overflow, a value of u64::MAX may be used even when the implementation doesn’t have a constant max value.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§