pub struct Duration { /* private fields */ }
Expand description
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§
source§impl Duration
impl Duration
sourcepub const NANOSECOND: Self = _
pub const NANOSECOND: Self = _
sourcepub const MICROSECOND: Self = _
pub const MICROSECOND: Self = _
sourcepub const MILLISECOND: Self = _
pub const MILLISECOND: Self = _
sourcepub const MIN: Self = _
pub const MIN: Self = _
The minimum possible duration. Adding any negative duration to this will cause an overflow.
sourcepub const MAX: Self = _
pub const MAX: Self = _
The maximum possible duration. Adding any positive duration to this will cause an overflow.
sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
sourcepub const fn unsigned_abs(self) -> StdDuration
pub const fn unsigned_abs(self) -> StdDuration
Convert the existing Duration
to a std::time::Duration
and its sign. This returns a
std::time::Duration
and does not saturate the returned value (unlike Duration::abs
).
sourcepub fn seconds_f64(seconds: f64) -> Self
pub fn seconds_f64(seconds: f64) -> Self
sourcepub fn seconds_f32(seconds: f32) -> Self
pub fn seconds_f32(seconds: f32) -> Self
sourcepub const fn milliseconds(milliseconds: i64) -> Self
pub const fn milliseconds(milliseconds: i64) -> Self
sourcepub const fn microseconds(microseconds: i64) -> Self
pub const fn microseconds(microseconds: i64) -> Self
sourcepub const fn nanoseconds(nanoseconds: i64) -> Self
pub const fn nanoseconds(nanoseconds: i64) -> Self
sourcepub const fn whole_weeks(self) -> i64
pub const fn whole_weeks(self) -> i64
sourcepub const fn whole_days(self) -> i64
pub const fn whole_days(self) -> i64
sourcepub const fn whole_hours(self) -> i64
pub const fn whole_hours(self) -> i64
sourcepub const fn whole_minutes(self) -> i64
pub const fn whole_minutes(self) -> i64
sourcepub const fn whole_seconds(self) -> i64
pub const fn whole_seconds(self) -> i64
sourcepub fn as_seconds_f64(self) -> f64
pub fn as_seconds_f64(self) -> f64
sourcepub fn as_seconds_f32(self) -> f32
pub fn as_seconds_f32(self) -> f32
sourcepub const fn whole_milliseconds(self) -> i128
pub const fn whole_milliseconds(self) -> i128
sourcepub const fn subsec_milliseconds(self) -> i16
pub const fn subsec_milliseconds(self) -> i16
sourcepub const fn whole_microseconds(self) -> i128
pub const fn whole_microseconds(self) -> i128
sourcepub const fn subsec_microseconds(self) -> i32
pub const fn subsec_microseconds(self) -> i32
sourcepub const fn whole_nanoseconds(self) -> i128
pub const fn whole_nanoseconds(self) -> i128
sourcepub const fn subsec_nanoseconds(self) -> i32
pub const fn subsec_nanoseconds(self) -> i32
sourcepub const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_add(self, rhs: Self) -> Option<Self>
sourcepub const fn checked_sub(self, rhs: Self) -> Option<Self>
pub const fn checked_sub(self, rhs: Self) -> Option<Self>
sourcepub const fn checked_mul(self, rhs: i32) -> Option<Self>
pub const fn checked_mul(self, rhs: i32) -> Option<Self>
Computes self * rhs
, returning None
if an overflow occurred.
sourcepub const fn checked_div(self, rhs: i32) -> Option<Self>
pub const fn checked_div(self, rhs: i32) -> Option<Self>
sourcepub const fn saturating_add(self, rhs: Self) -> Self
pub const fn saturating_add(self, rhs: Self) -> Self
Computes self + rhs
, saturating if an overflow occurred.
sourcepub const fn saturating_sub(self, rhs: Self) -> Self
pub const fn saturating_sub(self, rhs: Self) -> Self
Computes self - rhs
, saturating if an overflow occurred.
sourcepub const fn saturating_mul(self, rhs: i32) -> Self
pub const fn saturating_mul(self, rhs: i32) -> Self
Computes self * rhs
, saturating if an overflow occurred.
assert_eq!(5.seconds().saturating_mul(2), 10.seconds());
assert_eq!(5.seconds().saturating_mul(-2), (-10).seconds());
assert_eq!(5.seconds().saturating_mul(0), Duration::ZERO);
assert_eq!(Duration::MAX.saturating_mul(2), Duration::MAX);
assert_eq!(Duration::MIN.saturating_mul(2), Duration::MIN);
assert_eq!(Duration::MAX.saturating_mul(-2), Duration::MIN);
assert_eq!(Duration::MIN.saturating_mul(-2), Duration::MAX);
Trait Implementations§
source§impl Add<Duration> for PrimitiveDateTime
impl Add<Duration> for PrimitiveDateTime
source§impl Add<Duration> for SystemTime
impl Add<Duration> for SystemTime
source§impl Add<Duration> for Time
impl Add<Duration> for Time
source§impl AddAssign<Duration> for Date
impl AddAssign<Duration> for Date
source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+=
operation. Read moresource§impl AddAssign<Duration> for Duration
impl AddAssign<Duration> for Duration
source§fn add_assign(&mut self, rhs: StdDuration)
fn add_assign(&mut self, rhs: StdDuration)
+=
operation. Read moresource§impl AddAssign<Duration> for Duration
impl AddAssign<Duration> for Duration
source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+=
operation. Read moresource§impl AddAssign<Duration> for Instant
impl AddAssign<Duration> for Instant
source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+=
operation. Read moresource§impl AddAssign<Duration> for Instant
impl AddAssign<Duration> for Instant
source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+=
operation. Read moresource§impl AddAssign<Duration> for OffsetDateTime
impl AddAssign<Duration> for OffsetDateTime
source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+=
operation. Read moresource§impl AddAssign<Duration> for PrimitiveDateTime
impl AddAssign<Duration> for PrimitiveDateTime
source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+=
operation. Read moresource§impl AddAssign<Duration> for SystemTime
impl AddAssign<Duration> for SystemTime
source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+=
operation. Read moresource§impl AddAssign<Duration> for Time
impl AddAssign<Duration> for Time
source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+=
operation. Read moresource§impl AddAssign for Duration
impl AddAssign for Duration
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moresource§impl<'a> Deserialize<'a> for Duration
impl<'a> Deserialize<'a> for Duration
source§fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error>
source§impl Display for Duration
impl Display for Duration
The format returned by this implementation is not stable and must not be relied upon.
By default this produces an exact, full-precision printout of the duration.
For a concise, rounded printout instead, you can use the .N
format specifier:
For the purposes of this implementation, a day is exactly 24 hours and a minute is exactly 60 seconds.
source§impl DivAssign<f32> for Duration
impl DivAssign<f32> for Duration
source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/=
operation. Read moresource§impl DivAssign<f64> for Duration
impl DivAssign<f64> for Duration
source§fn div_assign(&mut self, rhs: f64)
fn div_assign(&mut self, rhs: f64)
/=
operation. Read moresource§impl DivAssign<i16> for Duration
impl DivAssign<i16> for Duration
source§fn div_assign(&mut self, rhs: i16)
fn div_assign(&mut self, rhs: i16)
/=
operation. Read moresource§impl DivAssign<i32> for Duration
impl DivAssign<i32> for Duration
source§fn div_assign(&mut self, rhs: i32)
fn div_assign(&mut self, rhs: i32)
/=
operation. Read moresource§impl DivAssign<i8> for Duration
impl DivAssign<i8> for Duration
source§fn div_assign(&mut self, rhs: i8)
fn div_assign(&mut self, rhs: i8)
/=
operation. Read moresource§impl DivAssign<u16> for Duration
impl DivAssign<u16> for Duration
source§fn div_assign(&mut self, rhs: u16)
fn div_assign(&mut self, rhs: u16)
/=
operation. Read moresource§impl DivAssign<u32> for Duration
impl DivAssign<u32> for Duration
source§fn div_assign(&mut self, rhs: u32)
fn div_assign(&mut self, rhs: u32)
/=
operation. Read moresource§impl DivAssign<u8> for Duration
impl DivAssign<u8> for Duration
source§fn div_assign(&mut self, rhs: u8)
fn div_assign(&mut self, rhs: u8)
/=
operation. Read moresource§impl MulAssign<f32> for Duration
impl MulAssign<f32> for Duration
source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*=
operation. Read moresource§impl MulAssign<f64> for Duration
impl MulAssign<f64> for Duration
source§fn mul_assign(&mut self, rhs: f64)
fn mul_assign(&mut self, rhs: f64)
*=
operation. Read moresource§impl MulAssign<i16> for Duration
impl MulAssign<i16> for Duration
source§fn mul_assign(&mut self, rhs: i16)
fn mul_assign(&mut self, rhs: i16)
*=
operation. Read moresource§impl MulAssign<i32> for Duration
impl MulAssign<i32> for Duration
source§fn mul_assign(&mut self, rhs: i32)
fn mul_assign(&mut self, rhs: i32)
*=
operation. Read moresource§impl MulAssign<i8> for Duration
impl MulAssign<i8> for Duration
source§fn mul_assign(&mut self, rhs: i8)
fn mul_assign(&mut self, rhs: i8)
*=
operation. Read moresource§impl MulAssign<u16> for Duration
impl MulAssign<u16> for Duration
source§fn mul_assign(&mut self, rhs: u16)
fn mul_assign(&mut self, rhs: u16)
*=
operation. Read moresource§impl MulAssign<u32> for Duration
impl MulAssign<u32> for Duration
source§fn mul_assign(&mut self, rhs: u32)
fn mul_assign(&mut self, rhs: u32)
*=
operation. Read moresource§impl MulAssign<u8> for Duration
impl MulAssign<u8> for Duration
source§fn mul_assign(&mut self, rhs: u8)
fn mul_assign(&mut self, rhs: u8)
*=
operation. Read moresource§impl Ord for Duration
impl Ord for Duration
source§impl PartialOrd<Duration> for Duration
impl PartialOrd<Duration> for Duration
source§impl PartialOrd<Duration> for Duration
impl PartialOrd<Duration> for Duration
source§impl PartialOrd for Duration
impl PartialOrd for Duration
source§impl Sub<Duration> for PrimitiveDateTime
impl Sub<Duration> for PrimitiveDateTime
source§impl Sub<Duration> for SystemTime
impl Sub<Duration> for SystemTime
source§impl Sub<Duration> for Time
impl Sub<Duration> for Time
source§impl SubAssign<Duration> for Date
impl SubAssign<Duration> for Date
source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
-=
operation. Read moresource§impl SubAssign<Duration> for Duration
impl SubAssign<Duration> for Duration
source§fn sub_assign(&mut self, rhs: StdDuration)
fn sub_assign(&mut self, rhs: StdDuration)
-=
operation. Read moresource§impl SubAssign<Duration> for Duration
impl SubAssign<Duration> for Duration
source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
-=
operation. Read moresource§impl SubAssign<Duration> for Instant
impl SubAssign<Duration> for Instant
source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
-=
operation. Read moresource§impl SubAssign<Duration> for Instant
impl SubAssign<Duration> for Instant
source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
-=
operation. Read moresource§impl SubAssign<Duration> for OffsetDateTime
impl SubAssign<Duration> for OffsetDateTime
source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
-=
operation. Read moresource§impl SubAssign<Duration> for PrimitiveDateTime
impl SubAssign<Duration> for PrimitiveDateTime
source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
-=
operation. Read moresource§impl SubAssign<Duration> for SystemTime
impl SubAssign<Duration> for SystemTime
source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
-=
operation. Read moresource§impl SubAssign<Duration> for Time
impl SubAssign<Duration> for Time
source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
-=
operation. Read moresource§impl SubAssign for Duration
impl SubAssign for Duration
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read moresource§impl TryFrom<Duration> for Duration
impl TryFrom<Duration> for Duration
§type Error = ConversionRange
type Error = ConversionRange
source§fn try_from(original: StdDuration) -> Result<Self, ConversionRange>
fn try_from(original: StdDuration) -> Result<Self, ConversionRange>
source§impl TryFrom<Duration> for Duration
impl TryFrom<Duration> for Duration
§type Error = ConversionRange
type Error = ConversionRange
impl Copy for Duration
impl Eq for Duration
impl StructuralPartialEq for Duration
Auto Trait Implementations§
impl Freeze for Duration
impl RefUnwindSafe for Duration
impl Send for Duration
impl Sync for Duration
impl Unpin for Duration
impl UnwindSafe for Duration
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)