pub trait NumericalDuration: Sealed {
// Required methods
fn nanoseconds(self) -> SignedDuration;
fn microseconds(self) -> SignedDuration;
fn milliseconds(self) -> SignedDuration;
fn seconds(self) -> SignedDuration;
fn minutes(self) -> SignedDuration;
fn hours(self) -> SignedDuration;
fn days(self) -> SignedDuration;
fn weeks(self) -> SignedDuration;
}Expand description
Create SignedDurations from numeric literals.
§Examples
Basic construction of SignedDurations.
assert_eq!(5.nanoseconds(), SignedDuration::nanoseconds(5));
assert_eq!(5.microseconds(), SignedDuration::microseconds(5));
assert_eq!(5.milliseconds(), SignedDuration::milliseconds(5));
assert_eq!(5.seconds(), SignedDuration::seconds(5));
assert_eq!(5.minutes(), SignedDuration::minutes(5));
assert_eq!(5.hours(), SignedDuration::hours(5));
assert_eq!(5.days(), SignedDuration::days(5));
assert_eq!(5.weeks(), SignedDuration::weeks(5));Signed integers work as well!
assert_eq!((-5).nanoseconds(), SignedDuration::nanoseconds(-5));
assert_eq!((-5).microseconds(), SignedDuration::microseconds(-5));
assert_eq!((-5).milliseconds(), SignedDuration::milliseconds(-5));
assert_eq!((-5).seconds(), SignedDuration::seconds(-5));
assert_eq!((-5).minutes(), SignedDuration::minutes(-5));
assert_eq!((-5).hours(), SignedDuration::hours(-5));
assert_eq!((-5).days(), SignedDuration::days(-5));
assert_eq!((-5).weeks(), SignedDuration::weeks(-5));Just like any other SignedDuration, 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§
Sourcefn nanoseconds(self) -> SignedDuration
fn nanoseconds(self) -> SignedDuration
Create a SignedDuration from the number of nanoseconds.
Sourcefn microseconds(self) -> SignedDuration
fn microseconds(self) -> SignedDuration
Create a SignedDuration from the number of microseconds.
Sourcefn milliseconds(self) -> SignedDuration
fn milliseconds(self) -> SignedDuration
Create a SignedDuration from the number of milliseconds.
Sourcefn seconds(self) -> SignedDuration
fn seconds(self) -> SignedDuration
Create a SignedDuration from the number of seconds.
Sourcefn minutes(self) -> SignedDuration
fn minutes(self) -> SignedDuration
Create a SignedDuration from the number of minutes.
Sourcefn hours(self) -> SignedDuration
fn hours(self) -> SignedDuration
Create a SignedDuration from the number of hours.
Sourcefn days(self) -> SignedDuration
fn days(self) -> SignedDuration
Create a SignedDuration from the number of days.
Sourcefn weeks(self) -> SignedDuration
fn weeks(self) -> SignedDuration
Create a SignedDuration from the number of weeks.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".