DurationExt

Trait DurationExt 

Source
pub trait DurationExt {
    // Required methods
    fn seconds(self) -> Duration;
    fn minutes(self) -> Duration;
    fn hours(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.

This crate is optimized for system timing (timeouts, sleeps, fixed cache TTLs). It explicitly excludes methods for units longer than hours (days, weeks) to prevent calendar errors related to Daylight Saving Time (DST) and time zones.

§Panics

  • Signed integers (i32, i64) panic if the value is negative.
  • Overflow panics for .minutes() and .hours() when the resulting seconds exceed u64::MAX.

§Examples

use duration_extender::DurationExt;
use std::time::Duration;

let timeout = 10.seconds();
let delay = 5.minutes();
 
// For a fixed 2-day duration, use the hour equivalent:
let fixed_long_wait = (2 * 24).hours();

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 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 f32

Source§

impl DurationExt for f64

Source§

impl DurationExt for i32

Source§

impl DurationExt for i64

Source§

impl DurationExt for u32

Source§

impl DurationExt for u64

Implementors§