Crates.io | rusty_time |
lib.rs | rusty_time |
version | 1.1.0 |
source | src |
created_at | 2020-06-04 17:55:13.476646 |
updated_at | 2023-11-11 00:13:40.808175 |
description | A simple timer |
homepage | https://github.com/cleancut/rusty_time |
repository | https://github.com/cleancut/rusty_time |
max_upload_size | |
id | 250096 |
size | 14,381 |
A simple timer. See also the reference docs on docs.rs
Add rusty_timer
to your Cargo.toml
with:
cargo add rusty_timer
Then use it like this:
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!");
}
All contributions are assumed to be dual-licensed under MIT/Apache-2.
Distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See license/APACHE and license/MIT.
If you like rusty_time
, please consider sponsoring me on GitHub. 💖