TimeProvider

Trait TimeProvider 

Source
pub trait TimeProvider {
    // Required methods
    fn current_time_ms(&self) -> Milliseconds;
    fn current_time_us(&self) -> Microseconds;
    fn last_time_ms(&self) -> Milliseconds;
    fn last_time_us(&self) -> Microseconds;
    fn update_last_time_ms(&mut self, time: Milliseconds);
    fn update_last_time_us(&mut self, time: Microseconds);

    // Provided methods
    fn elapsed_ms(&mut self) -> Milliseconds { ... }
    fn elapsed_us(&mut self) -> Microseconds { ... }
    fn reset(&mut self) { ... }
}
Expand description

Trait for providing time information to the animation system.

This trait abstracts time operations to support both std and no_std environments. Implementations can use system clocks, hardware timers, or external time sources.

Required Methods§

Source

fn current_time_ms(&self) -> Milliseconds

Get the current time in milliseconds since some reference point.

The reference point doesn’t matter as long as it’s consistent. This is typically used for calculating elapsed time between calls.

Source

fn current_time_us(&self) -> Microseconds

Get the current time in microseconds since some reference point.

This provides higher precision timing for fine-grained animations. The reference point should be the same as current_time_ms().

Source

fn last_time_ms(&self) -> Milliseconds

Get the last recorded time in milliseconds.

This is used internally by elapsed_ms().

Source

fn last_time_us(&self) -> Microseconds

Get the last recorded time in microseconds.

This is used internally by elapsed_us().

Source

fn update_last_time_ms(&mut self, time: Milliseconds)

Update the last recorded time in milliseconds.

This is used internally by elapsed_ms().

Source

fn update_last_time_us(&mut self, time: Microseconds)

Update the last recorded time in microseconds.

This is used internally by elapsed_us().

Provided Methods§

Source

fn elapsed_ms(&mut self) -> Milliseconds

Calculate elapsed time in milliseconds since the last call.

This is a convenience method that handles the delta calculation. The implementation should track the last time internally.

Source

fn elapsed_us(&mut self) -> Microseconds

Calculate elapsed time in microseconds since the last call.

This is a convenience method that handles the delta calculation. The implementation should track the last time internally.

Source

fn reset(&mut self)

Reset the time provider to start fresh timing.

This resets any internal state and starts timing from the current moment.

Implementors§

Source§

impl TimeProvider for ManualTimeProvider

Source§

impl TimeProvider for StdTimeProvider

Available on crate feature std only.
Source§

impl<F> TimeProvider for MonotonicTimeProvider<F>
where F: Fn() -> Microseconds,