pub trait ToTime {
    fn hours(self) -> Duration;
    fn minutes(self) -> Duration;
    fn seconds(self) -> Duration;
    fn milliseconds(self) -> Duration;
    fn microseconds(self) -> Duration;
    fn nanoseconds(self) -> Duration;
}
Available on crate feature integers only.
Expand description

Converts an integer to a Duration of the unit.

Required Methods

Creates a Duration of self hours.

Example
use core_extensions::ToTime;

use std::time::Duration;

assert_eq!(1  .hours(), Duration::from_secs(1  *3600));
assert_eq!(10 .hours(), Duration::from_secs(10 *3600));
assert_eq!(101.hours(), Duration::from_secs(101*3600));

Creates a Duration of self minutes.

Example
use core_extensions::ToTime;

use std::time::Duration;

assert_eq!(1  .minutes(), Duration::from_secs(1  *60));
assert_eq!(10 .minutes(), Duration::from_secs(10 *60));
assert_eq!(101.minutes(), Duration::from_secs(101*60));

Creates a Duration of self seconds

Example
use core_extensions::ToTime;

use std::time::Duration;

assert_eq!(1.seconds(), Duration::from_secs(1));
assert_eq!(10.seconds(), Duration::from_secs(10));
assert_eq!(101.seconds(), Duration::from_secs(101));

Creates a Duration of self milliseconds

Example
use core_extensions::ToTime;

use std::time::Duration;

assert_eq!(0.milliseconds(), Duration::from_millis(0));
assert_eq!(1.milliseconds(), Duration::from_millis(1));
assert_eq!(10.milliseconds(), Duration::from_millis(10));

Creates a Duration of self microseconds

Example
use core_extensions::ToTime;

use std::time::Duration;

assert_eq!(10.microseconds(), Duration::new(0,10_000));
assert_eq!(10_000_001.microseconds(), Duration::new(10,1_000));

Creates a Duration of self nanoseconds

Example
use core_extensions::ToTime;

use std::time::Duration;

assert_eq!(10.nanoseconds(), Duration::new(0,10));
assert_eq!(1_000_000.nanoseconds(), Duration::new(0,1_000_000));
assert_eq!(1_000_000_000.nanoseconds(), Duration::new(1,0));
assert_eq!(1_000_001_000.nanoseconds(), Duration::new(1,1_000));

Implementors