Struct SignedDuration
#[repr(C)]
pub struct SignedDuration { /* private fields */ }
A span of time with nanosecond precision.
Each SignedDuration 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 SignedDuration
const ZERO: Self = _;Equivalent to
0.seconds().# use ; assert_eq!;const NANOSECOND: Self = _;Equivalent to
1.nanoseconds().# use ; assert_eq!;const MICROSECOND: Self = _;Equivalent to
1.microseconds().# use ; assert_eq!;const MILLISECOND: Self = _;Equivalent to
1.milliseconds().# use ; assert_eq!;const SECOND: Self = _;Equivalent to
1.seconds().# use ; assert_eq!;const MINUTE: Self = _;Equivalent to
1.minutes().# use ; assert_eq!;const HOUR: Self = _;Equivalent to
1.hours().# use ; assert_eq!;const DAY: Self = _;Equivalent to
1.days().# use ; assert_eq!;const WEEK: Self = _;Equivalent to
1.weeks().# use ; assert_eq!;const MIN: Self = _;The minimum possible duration. Adding any negative duration to this will cause an overflow.
const MAX: Self = _;The maximum possible duration. Adding any positive duration to this will cause an overflow.
const fn is_zero(self) -> boolCheck if a duration is exactly zero.
# use NumericalDuration; assert!; assert!;const fn is_negative(self) -> boolCheck if a duration is negative.
# use NumericalDuration; assert!; assert!; assert!;const fn is_positive(self) -> boolCheck if a duration is positive.
# use NumericalDuration; assert!; assert!; assert!;const fn abs(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) -> StdDurationConvert the existing
SignedDurationto astd::time::Durationand its sign. This returns astd::time::Durationand does not saturate the returned value (unlikeSignedDuration::abs).# use ; assert_eq!; assert_eq!; assert_eq!;const fn new(seconds: i64, nanoseconds: i32) -> SelfCreate a new
SignedDurationwith 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
SignedDurationwith the given number of weeks. Equivalent toSignedDuration::seconds(weeks * 604_800).# use ; assert_eq!;Panics
This may panic if an overflow occurs.
const fn days(days: i64) -> SelfCreate a new
SignedDurationwith the given number of days. Equivalent toSignedDuration::seconds(days * 86_400).# use ; assert_eq!;Panics
This may panic if an overflow occurs.
const fn hours(hours: i64) -> SelfCreate a new
SignedDurationwith the given number of hours. Equivalent toSignedDuration::seconds(hours * 3_600).# use ; assert_eq!;Panics
This may panic if an overflow occurs.
const fn minutes(minutes: i64) -> SelfCreate a new
SignedDurationwith the given number of minutes. Equivalent toSignedDuration::seconds(minutes * 60).# use ; assert_eq!;Panics
This may panic if an overflow occurs.
const fn seconds(seconds: i64) -> SelfCreate a new
SignedDurationwith the given number of seconds.# use ; assert_eq!;const fn seconds_f64(seconds: f64) -> SelfCreates a new
SignedDurationfrom the specified number of seconds represented asf64.# use ; assert_eq!; assert_eq!;Panics
This may panic if
secondsisNaNor overflows the representable range ofSignedDuration.const fn seconds_f32(seconds: f32) -> SelfCreates a new
SignedDurationfrom the specified number of seconds represented asf32.# use ; assert_eq!; assert_eq!;Panics
This may panic if
secondsisNaNor overflows the representable range ofSignedDuration.const fn saturating_seconds_f64(seconds: f64) -> SelfCreates a new
SignedDurationfrom 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 aSignedDurationof 0 seconds.# use ; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn saturating_seconds_f32(seconds: f32) -> SelfCreates a new
SignedDurationfrom 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 aSignedDurationof 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
SignedDurationfrom the specified number of seconds represented asf64. ReturnsNoneif theSignedDurationcan'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
SignedDurationfrom the specified number of seconds represented asf32. ReturnsNoneif theSignedDurationcan't be represented.# use ; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn milliseconds(milliseconds: i64) -> SelfCreate a new
SignedDurationwith the given number of milliseconds.# use ; assert_eq!; assert_eq!;const fn microseconds(microseconds: i64) -> SelfCreate a new
SignedDurationwith the given number of microseconds.# use ; assert_eq!; assert_eq!;const fn nanoseconds(nanoseconds: i64) -> SelfCreate a new
SignedDurationwith the given number of nanoseconds.# use ; assert_eq!; assert_eq!;const fn nanoseconds_i128(nanoseconds: i128) -> SelfCreate a new
SignedDurationwith 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) -> i64Get the number of whole weeks in the duration.
# use NumericalDuration; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn whole_days(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) -> i64Get the number of whole hours in the duration.
# use NumericalDuration; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn whole_minutes(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) -> 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) -> f64Get the number of fractional seconds in the duration.
# use NumericalDuration; assert_eq!; assert_eq!;const fn as_seconds_f32(self) -> f32Get the number of fractional seconds in the duration.
# use NumericalDuration; assert_eq!; assert_eq!;const fn whole_milliseconds(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) -> 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) -> i128Get the number of whole microseconds in the duration.
# use NumericalDuration; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn subsec_microseconds(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) -> i128Get the number of nanoseconds in the duration.
# use NumericalDuration; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn subsec_nanoseconds(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, rhs: Self) -> Option<Self>Computes
self + rhs, returningNoneif an overflow occurred.# use ; assert_eq!; assert_eq!; assert_eq!;const fn checked_sub(self, rhs: Self) -> Option<Self>Computes
self - rhs, returningNoneif an overflow occurred.# use ; assert_eq!; assert_eq!; assert_eq!;const fn checked_mul(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, 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) -> Option<Self>Computes
-self, returningNoneif the result would overflow.# use NumericalDuration; # use SignedDuration; assert_eq!; assert_eq!;const fn saturating_add(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, rhs: Self) -> SelfComputes
self - rhs, saturating if an overflow occurred.# use ; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn saturating_mul(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!;
Trait Implementations
impl Add for SignedDuration
type Output = SignedDuration;fn add(self, rhs: Self) -> Self::OutputPanics
This may panic if an overflow occurs.
impl Add<Duration> for SignedDuration
type Output = SignedDuration;fn add(self, std_duration: StdDuration) -> Self::OutputPanics
This may panic if an overflow occurs.
impl AddAssign for SignedDuration
fn add_assign(&mut self, rhs: Self)Panics
This may panic if an overflow occurs.
impl AddAssign<Duration> for SignedDuration
fn add_assign(&mut self, rhs: StdDuration)Panics
This may panic if an overflow occurs.
impl Clone for SignedDuration
fn clone(&self) -> SignedDuration
impl Copy for SignedDuration
impl Debug for SignedDuration
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Default for SignedDuration
fn default() -> Self
impl Display for SignedDuration
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Div for SignedDuration
type Output = f64;fn div(self, rhs: Self) -> Self::OutputPanics
This may panic if
rhs == SignedDuration::ZERO.
impl Div<Duration> for SignedDuration
type Output = f64;fn div(self, rhs: StdDuration) -> Self::OutputPanics
This may panic if
rhs == SignedDuration::ZERO.
impl Div<f32> for SignedDuration
type Output = SignedDuration;fn div(self, rhs: f32) -> Self::OutputPanics
This may panic if an overflow occurs or if
rhs == 0.
impl Div<f64> for SignedDuration
type Output = SignedDuration;fn div(self, rhs: f64) -> Self::OutputPanics
This may panic if an overflow occurs or if
rhs == 0.
impl Div<i16> for SignedDuration
type Output = SignedDuration;fn div(self, rhs: i16) -> Self::OutputPanics
This may panic if an overflow occurs or if
rhs == 0.
impl Div<i32> for SignedDuration
type Output = SignedDuration;fn div(self, rhs: i32) -> Self::OutputPanics
This may panic if an overflow occurs or if
rhs == 0.
impl Div<i8> for SignedDuration
type Output = SignedDuration;fn div(self, rhs: i8) -> Self::OutputPanics
This may panic if an overflow occurs or if
rhs == 0.
impl Div<u16> for SignedDuration
type Output = SignedDuration;fn div(self, rhs: u16) -> Self::OutputPanics
This may panic if an overflow occurs or if
rhs == 0.
impl Div<u32> for SignedDuration
type Output = SignedDuration;fn div(self, rhs: u32) -> Self::OutputPanics
This may panic if an overflow occurs or if
rhs == 0.
impl Div<u8> for SignedDuration
type Output = SignedDuration;fn div(self, rhs: u8) -> Self::OutputPanics
This may panic if an overflow occurs or if
rhs == 0.
impl DivAssign<f32> for SignedDuration
fn div_assign(&mut self, rhs: f32)Panics
This may panic if an overflow occurs or if
rhs == 0.
impl DivAssign<f64> for SignedDuration
fn div_assign(&mut self, rhs: f64)Panics
This may panic if an overflow occurs or if
rhs == 0.
impl DivAssign<i16> for SignedDuration
fn div_assign(&mut self, rhs: i16)Panics
This may panic if an overflow occurs or if
rhs == 0.
impl DivAssign<i32> for SignedDuration
fn div_assign(&mut self, rhs: i32)Panics
This may panic if an overflow occurs or if
rhs == 0.
impl DivAssign<i8> for SignedDuration
fn div_assign(&mut self, rhs: i8)Panics
This may panic if an overflow occurs or if
rhs == 0.
impl DivAssign<u16> for SignedDuration
fn div_assign(&mut self, rhs: u16)Panics
This may panic if an overflow occurs or if
rhs == 0.
impl DivAssign<u32> for SignedDuration
fn div_assign(&mut self, rhs: u32)Panics
This may panic if an overflow occurs or if
rhs == 0.
impl DivAssign<u8> for SignedDuration
fn div_assign(&mut self, rhs: u8)Panics
This may panic if an overflow occurs or if
rhs == 0.
impl Eq for SignedDuration
impl Hash for SignedDuration
fn hash<H>(&self, state: &mut H) where H: Hasher,
impl Mul<f32> for SignedDuration
type Output = SignedDuration;fn mul(self, rhs: f32) -> Self::OutputPanics
This may panic if an overflow occurs.
impl Mul<f64> for SignedDuration
type Output = SignedDuration;fn mul(self, rhs: f64) -> Self::OutputPanics
This may panic if an overflow occurs.
impl Mul<i16> for SignedDuration
type Output = SignedDuration;fn mul(self, rhs: i16) -> Self::OutputPanics
This may panic if an overflow occurs.
impl Mul<i32> for SignedDuration
type Output = SignedDuration;fn mul(self, rhs: i32) -> Self::OutputPanics
This may panic if an overflow occurs.
impl Mul<i8> for SignedDuration
type Output = SignedDuration;fn mul(self, rhs: i8) -> Self::OutputPanics
This may panic if an overflow occurs.
impl Mul<u16> for SignedDuration
type Output = SignedDuration;fn mul(self, rhs: u16) -> Self::OutputPanics
This may panic if an overflow occurs.
impl Mul<u32> for SignedDuration
type Output = SignedDuration;fn mul(self, rhs: u32) -> Self::OutputPanics
This may panic if an overflow occurs.
impl Mul<u8> for SignedDuration
type Output = SignedDuration;fn mul(self, rhs: u8) -> Self::OutputPanics
This may panic if an overflow occurs.
impl MulAssign<f32> for SignedDuration
fn mul_assign(&mut self, rhs: f32)Panics
This may panic if an overflow occurs.
impl MulAssign<f64> for SignedDuration
fn mul_assign(&mut self, rhs: f64)Panics
This may panic if an overflow occurs.
impl MulAssign<i16> for SignedDuration
fn mul_assign(&mut self, rhs: i16)Panics
This may panic if an overflow occurs.
impl MulAssign<i32> for SignedDuration
fn mul_assign(&mut self, rhs: i32)Panics
This may panic if an overflow occurs.
impl MulAssign<i8> for SignedDuration
fn mul_assign(&mut self, rhs: i8)Panics
This may panic if an overflow occurs.
impl MulAssign<u16> for SignedDuration
fn mul_assign(&mut self, rhs: u16)Panics
This may panic if an overflow occurs.
impl MulAssign<u32> for SignedDuration
fn mul_assign(&mut self, rhs: u32)Panics
This may panic if an overflow occurs.
impl MulAssign<u8> for SignedDuration
fn mul_assign(&mut self, rhs: u8)Panics
This may panic if an overflow occurs.
impl Neg for SignedDuration
type Output = SignedDuration;fn neg(self) -> Self::OutputPanics
This may panic if an overflow occurs.
impl Ord for SignedDuration
fn cmp(&self, other: &Self) -> Ordering
impl PartialEq for SignedDuration
fn eq(&self, other: &Self) -> bool
impl PartialEq<Duration> for SignedDuration
fn eq(&self, rhs: &StdDuration) -> bool
impl PartialOrd for SignedDuration
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
impl PartialOrd<Duration> for SignedDuration
fn partial_cmp(&self, rhs: &StdDuration) -> Option<Ordering>
impl Sub for SignedDuration
type Output = SignedDuration;fn sub(self, rhs: Self) -> Self::OutputPanics
This may panic if an overflow occurs.
impl Sub<Duration> for SignedDuration
type Output = SignedDuration;fn sub(self, rhs: StdDuration) -> Self::OutputPanics
This may panic if an overflow occurs.
impl SubAssign for SignedDuration
fn sub_assign(&mut self, rhs: Self)Panics
This may panic if an overflow occurs.
impl SubAssign<Duration> for SignedDuration
fn sub_assign(&mut self, rhs: StdDuration)Panics
This may panic if an overflow occurs.
impl Sum for SignedDuration
fn sum<I>(iter: I) -> Self where I: Iterator<Item = Self>,
impl TryFrom<Duration> for SignedDuration
type Error = ConversionRange;fn try_from(original: StdDuration) -> Result<Self, ConversionRange>
impl<'a> Sum<&'a SignedDuration> for SignedDuration
fn sum<I>(iter: I) -> Self where I: Iterator<Item = &'a Self>,
Auto Trait Implementations
impl Freeze for SignedDuration
impl RefUnwindSafe for SignedDuration
impl Send for SignedDuration
impl Sync for SignedDuration
impl Unpin for SignedDuration
impl UnsafeUnpin for SignedDuration
impl UnwindSafe for SignedDuration
Blanket Implementations
impl<T> Any for SignedDuration
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for SignedDuration
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for SignedDuration
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for SignedDuration
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for SignedDuration
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for SignedDuration
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T> ToString for SignedDuration
where
T: Display + ?Sized,
fn to_string(&self) -> String
impl<T, U> Into<U> for SignedDuration
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for SignedDuration
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for SignedDuration
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>