pub trait DurationExt {
// Required methods
fn seconds(self) -> Duration;
fn minutes(self) -> Duration;
fn hours(self) -> Duration;
fn days(self) -> Duration;
fn weeks(self) -> Duration;
fn milliseconds(self) -> Duration;
fn microseconds(self) -> Duration;
fn nanoseconds(self) -> Duration;
}Expand description
An extension trait that adds fluent time unit methods to integer primitives, allowing for highly readable time duration creation.
§Panics
- Signed integers (
i32,i64) panic if the value is negative. - All integer types panic on overflow when creating a
Duration(e.g., very large minutes, hours, days, or weeks).
§Examples
use duration_extender::DurationExt;
use std::time::Duration;
let timeout = 10.seconds();
let delay = 5.minutes();
let long_wait = 2.days();
let total_time = 2.hours() + 30.minutes() + 15.seconds();
// Signed integers must be non-negative
let elapsed = 100.seconds(); // ✅ Works
// let bad = (-100).seconds(); // ❌ Panics!Required Methods§
Sourcefn days(self) -> Duration
fn days(self) -> Duration
Creates a Duration representing this many days (24 hours).
§Note
This is a fixed duration of 86,400 seconds. It does not account for calendar days or DST.
Sourcefn weeks(self) -> Duration
fn weeks(self) -> Duration
Creates a Duration representing this many weeks (7 days).
§Note
This is a fixed duration of 604,800 seconds. It does not account for calendar weeks or DST.
Sourcefn milliseconds(self) -> Duration
fn milliseconds(self) -> Duration
Creates a Duration representing this many milliseconds.
Sourcefn microseconds(self) -> Duration
fn microseconds(self) -> Duration
Creates a Duration representing this many microseconds.
Sourcefn nanoseconds(self) -> Duration
fn nanoseconds(self) -> Duration
Creates a Duration representing this many nanoseconds.