DurationExt

Trait DurationExt 

Source
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§

Source

fn seconds(self) -> Duration

Creates a Duration representing this many seconds.

Source

fn minutes(self) -> Duration

Creates a Duration representing this many minutes.

Source

fn hours(self) -> Duration

Creates a Duration representing this many hours.

Source

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.

Source

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.

Source

fn milliseconds(self) -> Duration

Creates a Duration representing this many milliseconds.

Source

fn microseconds(self) -> Duration

Creates a Duration representing this many microseconds.

Source

fn nanoseconds(self) -> Duration

Creates a Duration representing this many nanoseconds.

Implementations on Foreign Types§

Source§

impl DurationExt for i32

Source§

impl DurationExt for i64

Source§

impl DurationExt for u32

Source§

impl DurationExt for u64

Implementors§