Trait time::ext::NumericalStdDurationShort [−][src]
Create std::time::Duration
s from primitive and core numeric types. Unless
you are always expecting a std::time::Duration
, you should prefer to use
NumericalStdDuration
for clarity.
Due to limitations in rustc, these methods are currently not const fn
.
See this RFC for details.
Examples
Basic construction of std::time::Duration
s.
assert_eq!(5.nanoseconds(), Duration::from_nanos(5)); assert_eq!(5.microseconds(), Duration::from_micros(5)); assert_eq!(5.milliseconds(), Duration::from_millis(5)); assert_eq!(5.seconds(), Duration::from_secs(5)); assert_eq!(5.minutes(), Duration::from_secs(5 * 60)); assert_eq!(5.hours(), Duration::from_secs(5 * 3_600)); assert_eq!(5.days(), Duration::from_secs(5 * 86_400)); assert_eq!(5.weeks(), Duration::from_secs(5 * 604_800));
Just like any other std::time::Duration
, they can be added, subtracted,
etc.
assert_eq!(2.seconds() + 500.milliseconds(), 2_500.milliseconds()); assert_eq!(2.seconds() - 500.milliseconds(), 1_500.milliseconds());
When 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
fn nanoseconds(self) -> StdDuration
[src]
Create a std::time::Duration
from the number of nanoseconds.
fn microseconds(self) -> StdDuration
[src]
Create a std::time::Duration
from the number of microseconds.
fn milliseconds(self) -> StdDuration
[src]
Create a std::time::Duration
from the number of milliseconds.
fn seconds(self) -> StdDuration
[src]
Create a std::time::Duration
from the number of seconds.
fn minutes(self) -> StdDuration
[src]
Create a std::time::Duration
from the number of minutes.
fn hours(self) -> StdDuration
[src]
Create a std::time::Duration
from the number of hours.
fn days(self) -> StdDuration
[src]
Create a std::time::Duration
from the number of days.
fn weeks(self) -> StdDuration
[src]
Create a std::time::Duration
from the number of weeks.