Crate rusty_time

source ·
Expand description

rusty_time is a simple timer library.

Use it in a loop like this:

use std::time::{Duration, Instant};

use rusty_time::Timer;

fn main() {
    let mut timer = Timer::new(Duration::from_secs_f32(1.5));

    let mut start_time = Instant::now();
    loop {
        timer.tick(start_time.elapsed());
        start_time = Instant::now();
        println!(
            "Time on timer: {:.2}s ({:.1}%)",
            timer.remaining().as_secs_f32(),
            timer.percent_left() * 100.0
        );
        if timer.just_finished() {
            break;
        }
    }
    println!("Timer finished!");
}

Structs

  • A simple timer that is externally driven. .tick() must be called with a delta time for the timer to advance.