Struct Duration
struct Duration { ... }
A span of time with nanosecond precision.
Each Duration is composed of a whole number of seconds and a fractional part represented in
nanoseconds.
This implementation allows for negative durations, unlike core::time::Duration.
Implementations
impl Duration
const fn is_zero(self: Self) -> boolCheck if a duration is exactly zero.
# use NumericalDuration; assert!; assert!;const fn is_negative(self: Self) -> boolCheck if a duration is negative.
# use NumericalDuration; assert!; assert!; assert!;const fn is_positive(self: Self) -> boolCheck if a duration is positive.
# use NumericalDuration; assert!; assert!; assert!;const fn abs(self: Self) -> SelfGet the absolute value of the duration.
This method saturates the returned value if it would otherwise overflow.
# use NumericalDuration; assert_eq!; assert_eq!; assert_eq!;const fn unsigned_abs(self: Self) -> StdDurationConvert the existing
Durationto astd::time::Durationand its sign. This returns astd::time::Durationand does not saturate the returned value (unlikeDuration::abs).# use ; assert_eq!; assert_eq!; assert_eq!;const fn new(seconds: i64, nanoseconds: i32) -> SelfCreate a new
Durationwith the provided seconds and nanoseconds. If nanoseconds is at least ±109, it will wrap to the number of seconds.# use ; assert_eq!; assert_eq!; assert_eq!;Panics
This may panic if an overflow occurs.
const fn weeks(weeks: i64) -> SelfCreate a new
Durationwith the given number of weeks. Equivalent toDuration::seconds(weeks * 604_800).# use ; assert_eq!;Panics
This may panic if an overflow occurs.
const fn days(days: i64) -> SelfCreate a new
Durationwith the given number of days. Equivalent toDuration::seconds(days * 86_400).# use ; assert_eq!;Panics
This may panic if an overflow occurs.
const fn hours(hours: i64) -> SelfCreate a new
Durationwith the given number of hours. Equivalent toDuration::seconds(hours * 3_600).# use ; assert_eq!;Panics
This may panic if an overflow occurs.
const fn minutes(minutes: i64) -> SelfCreate a new
Durationwith the given number of minutes. Equivalent toDuration::seconds(minutes * 60).# use ; assert_eq!;Panics
This may panic if an overflow occurs.
const fn seconds(seconds: i64) -> SelfCreate a new
Durationwith the given number of seconds.# use ; assert_eq!;const fn seconds_f64(seconds: f64) -> SelfCreates a new
Durationfrom the specified number of seconds represented asf64.# use ; assert_eq!; assert_eq!;const fn seconds_f32(seconds: f32) -> SelfCreates a new
Durationfrom the specified number of seconds represented asf32.# use ; assert_eq!; assert_eq!;const fn saturating_seconds_f64(seconds: f64) -> SelfCreates a new
Durationfrom the specified number of seconds represented asf64. Any values that are out of bounds are saturated at the minimum or maximum respectively.NaNgets turned into aDurationof 0 seconds.# use ; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn saturating_seconds_f32(seconds: f32) -> SelfCreates a new
Durationfrom the specified number of seconds represented asf32. Any values that are out of bounds are saturated at the minimum or maximum respectively.NaNgets turned into aDurationof 0 seconds.# use ; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn checked_seconds_f64(seconds: f64) -> Option<Self>Creates a new
Durationfrom the specified number of seconds represented asf64. ReturnsNoneif theDurationcan't be represented.# use ; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn checked_seconds_f32(seconds: f32) -> Option<Self>Creates a new
Durationfrom the specified number of seconds represented asf32. ReturnsNoneif theDurationcan't be represented.# use ; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn milliseconds(milliseconds: i64) -> SelfCreate a new
Durationwith the given number of milliseconds.# use ; assert_eq!; assert_eq!;const fn microseconds(microseconds: i64) -> SelfCreate a new
Durationwith the given number of microseconds.# use ; assert_eq!; assert_eq!;const fn nanoseconds(nanoseconds: i64) -> SelfCreate a new
Durationwith the given number of nanoseconds.# use ; assert_eq!; assert_eq!;const fn nanoseconds_i128(nanoseconds: i128) -> SelfCreate a new
Durationwith the given number of nanoseconds.# use ; assert_eq!;Panics
This may panic if an overflow occurs. This may happen because the input range cannot be fully mapped to the output.
const fn whole_weeks(self: Self) -> i64Get the number of whole weeks in the duration.
# use NumericalDuration; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn whole_days(self: Self) -> i64Get the number of whole days in the duration.
# use NumericalDuration; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn whole_hours(self: Self) -> i64Get the number of whole hours in the duration.
# use NumericalDuration; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn whole_minutes(self: Self) -> i64Get the number of whole minutes in the duration.
# use NumericalDuration; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn whole_seconds(self: Self) -> i64Get the number of whole seconds in the duration.
# use NumericalDuration; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn as_seconds_f64(self: Self) -> f64Get the number of fractional seconds in the duration.
# use NumericalDuration; assert_eq!; assert_eq!;const fn as_seconds_f32(self: Self) -> f32Get the number of fractional seconds in the duration.
# use NumericalDuration; assert_eq!; assert_eq!;const fn whole_milliseconds(self: Self) -> i128Get the number of whole milliseconds in the duration.
# use NumericalDuration; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn subsec_milliseconds(self: Self) -> i16Get the number of milliseconds past the number of whole seconds.
Always in the range
-999..=999.# use NumericalDuration; assert_eq!; assert_eq!;const fn whole_microseconds(self: Self) -> i128Get the number of whole microseconds in the duration.
# use NumericalDuration; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn subsec_microseconds(self: Self) -> i32Get the number of microseconds past the number of whole seconds.
Always in the range
-999_999..=999_999.# use NumericalDuration; assert_eq!; assert_eq!;const fn whole_nanoseconds(self: Self) -> i128Get the number of nanoseconds in the duration.
# use NumericalDuration; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn subsec_nanoseconds(self: Self) -> i32Get the number of nanoseconds past the number of whole seconds.
The returned value will always be in the range
-999_999_999..=999_999_999.# use NumericalDuration; assert_eq!; assert_eq!;const fn checked_add(self: Self, rhs: Self) -> Option<Self>Computes
self + rhs, returningNoneif an overflow occurred.# use ; assert_eq!; assert_eq!; assert_eq!;const fn checked_sub(self: Self, rhs: Self) -> Option<Self>Computes
self - rhs, returningNoneif an overflow occurred.# use ; assert_eq!; assert_eq!; assert_eq!;const fn checked_mul(self: Self, rhs: i32) -> Option<Self>Computes
self * rhs, returningNoneif an overflow occurred.# use ; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn checked_div(self: Self, rhs: i32) -> Option<Self>Computes
self / rhs, returningNoneifrhs == 0or if the result would overflow.# use NumericalDuration; assert_eq!; assert_eq!; assert_eq!;const fn checked_neg(self: Self) -> Option<Self>Computes
-self, returningNoneif the result would overflow.# use NumericalDuration; # use Duration; assert_eq!; assert_eq!;const fn saturating_add(self: Self, rhs: Self) -> SelfComputes
self + rhs, saturating if an overflow occurred.# use ; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn saturating_sub(self: Self, rhs: Self) -> SelfComputes
self - rhs, saturating if an overflow occurred.# use ; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn saturating_mul(self: Self, rhs: i32) -> SelfComputes
self * rhs, saturating if an overflow occurred.# use ; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;
impl Add for Duration
fn add(self: Self, std_duration: StdDuration) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl Add for Duration
fn add(self: Self, rhs: Self) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl AddAssign for Duration
fn add_assign(self: &mut Self, rhs: StdDuration)Panics
This may panic if an overflow occurs.
impl AddAssign for Duration
fn add_assign(self: &mut Self, rhs: Self)Panics
This may panic if an overflow occurs.
impl Clone for Duration
fn clone(self: &Self) -> Duration
impl Copy for Duration
impl Debug for Duration
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Default for Duration
fn default() -> Self
impl Display for Duration
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Div for Duration
fn div(self: Self, rhs: Self) -> <Self as >::Output
impl Div for Duration
fn div(self: Self, rhs: u32) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl Div for Duration
fn div(self: Self, rhs: f64) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl Div for Duration
fn div(self: Self, rhs: u8) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl Div for Duration
fn div(self: Self, rhs: StdDuration) -> <Self as >::Output
impl Div for Duration
fn div(self: Self, rhs: i16) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl Div for Duration
fn div(self: Self, rhs: i8) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl Div for Duration
fn div(self: Self, rhs: u16) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl Div for Duration
fn div(self: Self, rhs: i32) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl Div for Duration
fn div(self: Self, rhs: f32) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl DivAssign for Duration
fn div_assign(self: &mut Self, rhs: u32)Panics
This may panic if an overflow occurs.
impl DivAssign for Duration
fn div_assign(self: &mut Self, rhs: f32)Panics
This may panic if an overflow occurs.
impl DivAssign for Duration
fn div_assign(self: &mut Self, rhs: u8)Panics
This may panic if an overflow occurs.
impl DivAssign for Duration
fn div_assign(self: &mut Self, rhs: i16)Panics
This may panic if an overflow occurs.
impl DivAssign for Duration
fn div_assign(self: &mut Self, rhs: i8)Panics
This may panic if an overflow occurs.
impl DivAssign for Duration
fn div_assign(self: &mut Self, rhs: u16)Panics
This may panic if an overflow occurs.
impl DivAssign for Duration
fn div_assign(self: &mut Self, rhs: i32)Panics
This may panic if an overflow occurs.
impl DivAssign for Duration
fn div_assign(self: &mut Self, rhs: f64)Panics
This may panic if an overflow occurs.
impl Eq for Duration
impl Freeze for Duration
impl Hash for Duration
fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)
impl Mul for Duration
fn mul(self: Self, rhs: i16) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl Mul for Duration
fn mul(self: Self, rhs: f32) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl Mul for Duration
fn mul(self: Self, rhs: u16) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl Mul for Duration
fn mul(self: Self, rhs: i8) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl Mul for Duration
fn mul(self: Self, rhs: i32) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl Mul for Duration
fn mul(self: Self, rhs: f64) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl Mul for Duration
fn mul(self: Self, rhs: u32) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl Mul for Duration
fn mul(self: Self, rhs: u8) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl MulAssign for Duration
fn mul_assign(self: &mut Self, rhs: u8)Panics
This may panic if an overflow occurs.
impl MulAssign for Duration
fn mul_assign(self: &mut Self, rhs: i16)Panics
This may panic if an overflow occurs.
impl MulAssign for Duration
fn mul_assign(self: &mut Self, rhs: u16)Panics
This may panic if an overflow occurs.
impl MulAssign for Duration
fn mul_assign(self: &mut Self, rhs: i8)Panics
This may panic if an overflow occurs.
impl MulAssign for Duration
fn mul_assign(self: &mut Self, rhs: i32)Panics
This may panic if an overflow occurs.
impl MulAssign for Duration
fn mul_assign(self: &mut Self, rhs: f64)Panics
This may panic if an overflow occurs.
impl MulAssign for Duration
fn mul_assign(self: &mut Self, rhs: f32)Panics
This may panic if an overflow occurs.
impl MulAssign for Duration
fn mul_assign(self: &mut Self, rhs: u32)Panics
This may panic if an overflow occurs.
impl Neg for Duration
fn neg(self: Self) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl Ord for Duration
fn cmp(self: &Self, other: &Duration) -> Ordering
impl PartialEq for Duration
fn eq(self: &Self, rhs: &StdDuration) -> bool
impl PartialEq for Duration
fn eq(self: &Self, other: &Duration) -> bool
impl PartialOrd for Duration
fn partial_cmp(self: &Self, rhs: &StdDuration) -> Option<Ordering>
impl PartialOrd for Duration
fn partial_cmp(self: &Self, other: &Duration) -> Option<Ordering>
impl RefUnwindSafe for Duration
impl Send for Duration
impl StructuralPartialEq for Duration
impl Sub for Duration
fn sub(self: Self, rhs: StdDuration) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl Sub for Duration
fn sub(self: Self, rhs: Self) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl SubAssign for Duration
fn sub_assign(self: &mut Self, rhs: Self)Panics
This may panic if an overflow occurs.
impl SubAssign for Duration
fn sub_assign(self: &mut Self, rhs: StdDuration)Panics
This may panic if an overflow occurs.
impl Sum for Duration
fn sum<I>(iter: I) -> Self where I: Iterator<Item = Self>
impl Sync for Duration
impl TryFrom for Duration
fn try_from(original: StdDuration) -> Result<Self, ConversionRange>
impl Unpin for Duration
impl UnsafeUnpin for Duration
impl UnwindSafe for Duration
impl<'a> Sum for Duration
fn sum<I>(iter: I) -> Self where I: Iterator<Item = &'a Self>
impl<T> Any for Duration
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Duration
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Duration
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Duration
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Duration
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Duration
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> ToString for Duration
fn to_string(self: &Self) -> String
impl<T, U> Into for Duration
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Duration
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Duration
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>