Skip to main content

Duration

Struct Duration 

Source
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

Source

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

Source

pub const ZERO: Self

No time.

Source

pub const MAX: Self

The longest representable duration, u64::MAX nanoseconds: about 584 years.

Source

pub const fn from_nanos(nanos: u64) -> Self

nanos nanoseconds.

Source

pub const fn from_micros(micros: u64) -> Self

micros microseconds, saturating at Duration::MAX.

Source

pub const fn from_millis(millis: u64) -> Self

millis milliseconds, saturating at Duration::MAX.

Source

pub const fn from_secs(secs: u64) -> Self

secs seconds, saturating at Duration::MAX.

Source

pub const fn try_from_micros(micros: u64) -> Option<Self>

micros microseconds, or None past Duration::MAX.

Source

pub const fn try_from_millis(millis: u64) -> Option<Self>

millis milliseconds, or None past Duration::MAX.

Source

pub const fn try_from_secs(secs: u64) -> Option<Self>

secs seconds, or None past Duration::MAX.

Source

pub const fn as_nanos(self) -> u64

The length in nanoseconds.

Source

pub const fn is_zero(self) -> bool

Whether the length is zero.

Source

pub const fn as_micros(self) -> u64

The whole microseconds in the length, rounded toward zero.

Source

pub const fn as_millis(self) -> u64

The whole milliseconds in the length, rounded toward zero.

Source

pub const fn as_secs(self) -> u64

The whole seconds in the length, rounded toward zero.

Source

pub const fn checked_add(self, other: Self) -> Option<Self>

self + other, or None past Duration::MAX.

Source

pub const fn saturating_add(self, other: Self) -> Self

self + other, clamped at Duration::MAX.

Source

pub const fn checked_sub(self, other: Self) -> Option<Self>

self - other, or None below zero.

Source

pub const fn saturating_sub(self, other: Self) -> Self

self - other, clamped at zero.

Source

pub const fn checked_mul(self, factor: u32) -> Option<Self>

self times factor, or None past Duration::MAX.

Source

pub const fn saturating_mul(self, factor: u32) -> Self

self times factor, clamped at Duration::MAX.

Source

pub const fn min(self, other: Self) -> Self

The shorter of self and other: Ord::min for a const context.

Source

pub const fn max(self, other: Self) -> Self

The longer of self and other: Ord::max for a const context.

Source

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 Add for Duration

Source§

fn add(self, rhs: Self) -> Self

Saturating, as Duration::saturating_add.

Source§

type Output = Duration

The resulting type after applying the + operator.
Source§

impl Add<Duration> for Instant

Source§

fn add(self, rhs: Duration) -> Self

Saturating, as Instant::saturating_add.

Source§

type Output = Instant

The resulting type after applying the + operator.
Source§

impl AddAssign for Duration

Source§

fn add_assign(&mut self, rhs: Self)

Saturating, as Duration::saturating_add.

Source§

impl AddAssign<Duration> for Instant

Source§

fn add_assign(&mut self, rhs: Duration)

Saturating, as Instant::saturating_add.

Source§

impl Clone for Duration

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Duration

Source§

impl Debug for Duration

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Duration

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Duration

Source§

impl From<Duration> for Duration

Source§

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 Hash for Duration

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Duration

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Duration

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Duration

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for Duration

Source§

impl Sub for Duration

Source§

fn sub(self, rhs: Self) -> Self

Saturating, as Duration::saturating_sub.

Source§

type Output = Duration

The resulting type after applying the - operator.
Source§

impl Sub<Duration> for Instant

Source§

fn sub(self, rhs: Duration) -> Self

Saturating, as Instant::saturating_sub.

Source§

type Output = Instant

The resulting type after applying the - operator.
Source§

impl SubAssign for Duration

Source§

fn sub_assign(&mut self, rhs: Self)

Saturating, as Duration::saturating_sub.

Source§

impl SubAssign<Duration> for Instant

Source§

fn sub_assign(&mut self, rhs: Duration)

Saturating, as Instant::saturating_sub.

Source§

impl TryFrom<Duration> for Duration

Source§

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.

Source§

type Error = DurationTooLong

The type returned in the event of a conversion error.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.