Trait time::ext::NumericalStdDuration
source · pub trait NumericalStdDuration: Sealed {
// Required methods
fn std_nanoseconds(self) -> StdDuration;
fn std_microseconds(self) -> StdDuration;
fn std_milliseconds(self) -> StdDuration;
fn std_seconds(self) -> StdDuration;
fn std_minutes(self) -> StdDuration;
fn std_hours(self) -> StdDuration;
fn std_days(self) -> StdDuration;
fn std_weeks(self) -> StdDuration;
}
Expand description
Create std::time::Duration
s from numeric literals.
Examples
Basic construction of std::time::Duration
s.
assert_eq!(5.std_nanoseconds(), Duration::from_nanos(5));
assert_eq!(5.std_microseconds(), Duration::from_micros(5));
assert_eq!(5.std_milliseconds(), Duration::from_millis(5));
assert_eq!(5.std_seconds(), Duration::from_secs(5));
assert_eq!(5.std_minutes(), Duration::from_secs(5 * 60));
assert_eq!(5.std_hours(), Duration::from_secs(5 * 3_600));
assert_eq!(5.std_days(), Duration::from_secs(5 * 86_400));
assert_eq!(5.std_weeks(), Duration::from_secs(5 * 604_800));
RunJust like any other std::time::Duration
, they can be added, subtracted, etc.
assert_eq!(
2.std_seconds() + 500.std_milliseconds(),
2_500.std_milliseconds()
);
assert_eq!(
2.std_seconds() - 500.std_milliseconds(),
1_500.std_milliseconds()
);
RunWhen called on floating point values, any remainder of the floating point value will be truncated. Keep in mind that floating point numbers are inherently imprecise and have limited capacity.
Required Methods§
sourcefn std_nanoseconds(self) -> StdDuration
fn std_nanoseconds(self) -> StdDuration
Create a std::time::Duration
from the number of nanoseconds.
sourcefn std_microseconds(self) -> StdDuration
fn std_microseconds(self) -> StdDuration
Create a std::time::Duration
from the number of microseconds.
sourcefn std_milliseconds(self) -> StdDuration
fn std_milliseconds(self) -> StdDuration
Create a std::time::Duration
from the number of milliseconds.
sourcefn std_seconds(self) -> StdDuration
fn std_seconds(self) -> StdDuration
Create a std::time::Duration
from the number of seconds.
sourcefn std_minutes(self) -> StdDuration
fn std_minutes(self) -> StdDuration
Create a std::time::Duration
from the number of minutes.
sourcefn std_hours(self) -> StdDuration
fn std_hours(self) -> StdDuration
Create a std::time::Duration
from the number of hours.
sourcefn std_days(self) -> StdDuration
fn std_days(self) -> StdDuration
Create a std::time::Duration
from the number of days.
sourcefn std_weeks(self) -> StdDuration
fn std_weeks(self) -> StdDuration
Create a std::time::Duration
from the number of weeks.