I made a tiny crate so you can write 5.minutes() instead of Duration::from_secs(300)
I made a tiny crate so you can write 5.minutes() instead of Duration::from_secs(300)
I kept copy-pasting this trait into my projects, so I finally published it as a crate.
Before:
let timeout = Duration::from_secs(30);
let delay = Duration::from_secs(5 * 60);
let cache_ttl = Duration::from_secs(24 * 60 * 60);
After:
use duration_extender::DurationExt;
let timeout = 30.seconds();
let delay = 5.minutes();
let cache_ttl = 1.days();
Features:
- Zero dependencies
- Works with u64, u32, i64, i32
- Never panics (saturating arithmetic)
- Supports seconds, minutes, hours, days, weeks, milliseconds, microseconds, nanoseconds
Crates.io: https://crates.io/crates/duration-extender
GitHub: https://github.com/durationextender/duration-extender-rs
This is my first published crate, so any feedback is appreciated!