simpler_timer 0.1.0

A very simple timer library with limited, but straight-forward functionality
Documentation

simple_timer

A simple timer mechanism to track arbitrary timeouts. It doesn't do anything fancy, e.g. no callbacks upon expiry, just give it a Duration and poll if the timer is expired. Timers can be reset and reused for periodic contexts, such as a simple time based control loop.

Example

use std::time::Duration;

// 100ms timer
let tick = Timer::with_duration(Duration::from_millis(100));
// 1 sec timer
let end = Timer::with_duration(Duration::from_secs(1));

loop {
if tick.expired() {
// do something interesting
println!("tick");
tick.reset();
}

if end.expired() { 
// don't reset, let's get out of here
break; 
}
}

println!("total time: {}ms", end.elapsed().as_millis());

The decision was made intentionally to only require a &self for resetting a timer so that another object can own a Timer and not require &mut self of the object owning the timer.