/// Sealed trait to prevent downstream implementations. mod sealed { /// A trait that cannot be implemented by downstream users. pubtrait Sealed {} impl Sealed for i64 {} impl Sealed for f64 {}
}
/// Create [`Duration`]s from numeric literals. /// /// # Examples /// /// Basic construction of [`Duration`]s. /// /// ```rust /// # use time::{Duration, ext::NumericalDuration}; /// assert_eq!(5.nanoseconds(), Duration::nanoseconds(5)); /// assert_eq!(5.microseconds(), Duration::microseconds(5)); /// assert_eq!(5.milliseconds(), Duration::milliseconds(5)); /// assert_eq!(5.seconds(), Duration::seconds(5)); /// assert_eq!(5.minutes(), Duration::minutes(5)); /// assert_eq!(5.hours(), Duration::hours(5)); /// assert_eq!(5.days(), Duration::days(5)); /// assert_eq!(5.weeks(), Duration::weeks(5)); /// ``` /// /// Signed integers work as well! /// /// ```rust /// # use time::{Duration, ext::NumericalDuration}; /// assert_eq!((-5).nanoseconds(), Duration::nanoseconds(-5)); /// assert_eq!((-5).microseconds(), Duration::microseconds(-5)); /// assert_eq!((-5).milliseconds(), Duration::milliseconds(-5)); /// assert_eq!((-5).seconds(), Duration::seconds(-5)); /// assert_eq!((-5).minutes(), Duration::minutes(-5)); /// assert_eq!((-5).hours(), Duration::hours(-5)); /// assert_eq!((-5).days(), Duration::days(-5)); /// assert_eq!((-5).weeks(), Duration::weeks(-5)); /// ``` /// /// Just like any other [`Duration`], they can be added, subtracted, etc. /// /// ```rust /// # use time::ext::NumericalDuration; /// 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. pubtrait NumericalDuration: sealed::Sealed { /// Create a [`Duration`] from the number of nanoseconds. fn nanoseconds(self) -> Duration; /// Create a [`Duration`] from the number of microseconds. fn microseconds(self) -> Duration; /// Create a [`Duration`] from the number of milliseconds. fn milliseconds(self) -> Duration; /// Create a [`Duration`] from the number of seconds. fn seconds(self) -> Duration; /// Create a [`Duration`] from the number of minutes. fn minutes(self) -> Duration; /// Create a [`Duration`] from the number of hours. fn hours(self) -> Duration; /// Create a [`Duration`] from the number of days. fn days(self) -> Duration; /// Create a [`Duration`] from the number of weeks. fn weeks(self) -> Duration;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.