Trait DurationNumExt

Source
pub trait DurationNumExt: DurationNumExtFallible {
    // Provided methods
    fn seconds(&self) -> Duration { ... }
    fn milliseconds(&self) -> Duration { ... }
    fn microseconds(&self) -> Duration { ... }
    fn nanoseconds(&self) -> Duration { ... }
    fn minutes(&self) -> Duration { ... }
    fn hours(&self) -> Duration { ... }
    fn days(&self) -> Duration { ... }
}
Expand description

Extension methods for constructing std::time::Duration with numbers.

§Note

This trait is not implemented for the Duration, for extension methods operating on a Duration, see crate::time::DurationExt for more information.

Provided Methods§

Source

fn seconds(&self) -> Duration

Create a Duration, using the postfix syntax.

§Example
use rs_std_ext::time::DurationNumExt;
use std::time::Duration;

assert_eq!(10u8.seconds(), Duration::from_secs(10u64));
§Panics

This function panics if the number is too large or negative.

Source

fn milliseconds(&self) -> Duration

Create a Duration, using the postfix syntax.

§Example
use rs_std_ext::time::DurationNumExt;
use std::time::Duration;

assert_eq!(10u8.milliseconds(), Duration::from_millis(10u64));
§Panics

This function panics if the number is too large or negative.

Source

fn microseconds(&self) -> Duration

Create a Duration, using the postfix syntax.

§Example
use rs_std_ext::time::DurationNumExt;
use std::time::Duration;

assert_eq!(10u8.microseconds(), Duration::from_micros(10u64));
§Panics

This function panics if the number is too large or negative.

Source

fn nanoseconds(&self) -> Duration

Create a Duration, using the postfix syntax.

§Example
use rs_std_ext::time::DurationNumExt;
use std::time::Duration;

assert_eq!(10u8.nanoseconds(), Duration::from_nanos(10u64));
§Panics

This function panics if the number is too large or negative.

Source

fn minutes(&self) -> Duration

Create a Duration, using the postfix syntax.

§Example
use rs_std_ext::time::DurationNumExt;
use std::time::Duration;

assert_eq!(10u128.minutes(), Duration::from_secs(10u64 * 60));
Source

fn hours(&self) -> Duration

Create a Duration, using the postfix syntax.

§Example
use rs_std_ext::time::DurationNumExt;
use std::time::Duration;

assert_eq!(10u128.hours(), Duration::from_secs(10u64 * 60 * 60));
Source

fn days(&self) -> Duration

Create a Duration, using the postfix syntax.

§Example
use rs_std_ext::time::DurationNumExt;
use std::time::Duration;

assert_eq!(10u128.days(), Duration::from_secs(10u64 * 60 * 60 * 24));

Implementations on Foreign Types§

Source§

impl DurationNumExt for f32

Source§

impl DurationNumExt for f64

Source§

impl DurationNumExt for i8

Source§

impl DurationNumExt for i16

Source§

impl DurationNumExt for i32

Source§

impl DurationNumExt for i64

Source§

impl DurationNumExt for i128

Source§

impl DurationNumExt for u8

Source§

impl DurationNumExt for u16

Source§

impl DurationNumExt for u32

Source§

impl DurationNumExt for u64

Source§

impl DurationNumExt for u128

Implementors§