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.

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 happen before the overflow occurs if start were called now.

This value is not necessarily constant as implementations built on top of continuously running timers will have shrinking amount of time left.

Source

fn max_nanos(&self) -> u64

The (inclusive) maximum number of nanoseconds that can happen before the overflow occurs if start were called now.

This value is not necessarily constant as implementations built on top of continuously running timers will have shrinking amount of time left.

Source

fn max_micros(&self) -> u64

The (inclusive) maximum number of microseconds that can happen before the overflow occurs if start were called now.

This value is not necessarily constant as implementations built on top of continuously running timers will have shrinking amount of time left.

Source

fn max_millis(&self) -> u64

The (inclusive) maximum number of milliseconds that can happen before the overflow occurs if start were called now.

This value is not necessarily constant as implementations built on top of continuously running timers will have shrinking amount of time left.

Source

fn max_secs(&self) -> u64

The (inclusive) maximum number of seconds that can happen before the overflow occurs if start were called now.

This value is not necessarily constant as implementations built on top of continuously running timers will have shrinking amount of time left.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§