pub struct Duration(/* private fields */);Expand description
A length of time, in nanoseconds on a u64: at most about 584 years.
+ and - saturate at Duration::MAX and at zero. The default is
Duration::ZERO.
The try_from_* constructors return None where the others saturate:
the try_ prefix on an Option, as chrono’s TimeDelta::try_seconds
has it.
Implementations§
Source§impl Duration
impl Duration
Sourcepub const fn saturating_from_core(duration: Duration) -> Self
pub const fn saturating_from_core(duration: Duration) -> Self
duration, clamped at Duration::MAX, about 584 years: for a
host mapping its own clock onto the timeline, where a time that far
out means never. A length that must fit, from configuration say,
goes through Duration::try_from instead, which refuses one too long.
Source§impl Duration
impl Duration
Sourcepub const fn from_nanos(nanos: u64) -> Self
pub const fn from_nanos(nanos: u64) -> Self
nanos nanoseconds.
Sourcepub const fn from_micros(micros: u64) -> Self
pub const fn from_micros(micros: u64) -> Self
micros microseconds, saturating at Duration::MAX.
Sourcepub const fn from_millis(millis: u64) -> Self
pub const fn from_millis(millis: u64) -> Self
millis milliseconds, saturating at Duration::MAX.
Sourcepub const fn from_secs(secs: u64) -> Self
pub const fn from_secs(secs: u64) -> Self
secs seconds, saturating at Duration::MAX.
Sourcepub const fn try_from_micros(micros: u64) -> Option<Self>
pub const fn try_from_micros(micros: u64) -> Option<Self>
micros microseconds, or None past Duration::MAX.
Sourcepub const fn try_from_millis(millis: u64) -> Option<Self>
pub const fn try_from_millis(millis: u64) -> Option<Self>
millis milliseconds, or None past Duration::MAX.
Sourcepub const fn try_from_secs(secs: u64) -> Option<Self>
pub const fn try_from_secs(secs: u64) -> Option<Self>
secs seconds, or None past Duration::MAX.
Sourcepub const fn checked_add(self, other: Self) -> Option<Self>
pub const fn checked_add(self, other: Self) -> Option<Self>
self + other, or None past Duration::MAX.
Sourcepub const fn saturating_add(self, other: Self) -> Self
pub const fn saturating_add(self, other: Self) -> Self
self + other, clamped at Duration::MAX.
Sourcepub const fn checked_sub(self, other: Self) -> Option<Self>
pub const fn checked_sub(self, other: Self) -> Option<Self>
self - other, or None below zero.
Sourcepub const fn saturating_sub(self, other: Self) -> Self
pub const fn saturating_sub(self, other: Self) -> Self
self - other, clamped at zero.
Sourcepub const fn checked_mul(self, factor: u32) -> Option<Self>
pub const fn checked_mul(self, factor: u32) -> Option<Self>
self times factor, or None past Duration::MAX.
Sourcepub const fn saturating_mul(self, factor: u32) -> Self
pub const fn saturating_mul(self, factor: u32) -> Self
self times factor, clamped at Duration::MAX.
Sourcepub const fn min(self, other: Self) -> Self
pub const fn min(self, other: Self) -> Self
The shorter of self and other: Ord::min for a const
context.
Sourcepub const fn max(self, other: Self) -> Self
pub const fn max(self, other: Self) -> Self
The longer of self and other: Ord::max for a const
context.
Sourcepub const fn checked_rem(self, divisor: Self) -> Option<Self>
pub const fn checked_rem(self, divisor: Self) -> Option<Self>
What is left of self after taking out as many whole divisors as
fit, or None for a zero divisor: the offset into a repeating
cycle, say.
It takes one step per bit of the quotient, without a 64-bit division routine (see the crate docs).
Trait Implementations§
Source§impl AddAssign for Duration
impl AddAssign for Duration
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Saturating, as Duration::saturating_add.
Source§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)
Saturating, as Instant::saturating_add.
impl Copy for Duration
impl Eq for Duration
Source§impl From<Duration> for Duration
impl From<Duration> for Duration
Source§fn from(duration: Duration) -> Self
fn from(duration: Duration) -> Self
The same length, exactly. Splitting it into seconds and nanoseconds takes no 64-bit division routine (see the crate docs).
Source§impl Ord for Duration
impl Ord for Duration
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Duration
impl PartialOrd for Duration
impl StructuralPartialEq for Duration
Source§impl SubAssign for Duration
impl SubAssign for Duration
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Saturating, as Duration::saturating_sub.
Source§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)
Saturating, as Instant::saturating_sub.
Source§impl TryFrom<Duration> for Duration
impl TryFrom<Duration> for Duration
Source§fn try_from(duration: Duration) -> Result<Self, DurationTooLong>
fn try_from(duration: Duration) -> Result<Self, DurationTooLong>
The same length, or DurationTooLong for one past
Duration::MAX: a core::time::Duration reaches about 584
billion years.