Struct time::Duration

source ·
pub struct Duration { /* private fields */ }
Expand description

ISO 8601 time duration with nanosecond precision. This also allows for the negative duration; see individual methods for details.

Implementations§

source§

impl Duration

source

pub fn weeks(weeks: i64) -> Duration

Makes a new Duration with given number of weeks. Equivalent to Duration::seconds(weeks * 7 * 24 * 60 * 60) with overflow checks. Panics when the duration is out of bounds.

source

pub fn days(days: i64) -> Duration

Makes a new Duration with given number of days. Equivalent to Duration::seconds(days * 24 * 60 * 60) with overflow checks. Panics when the duration is out of bounds.

source

pub fn hours(hours: i64) -> Duration

Makes a new Duration with given number of hours. Equivalent to Duration::seconds(hours * 60 * 60) with overflow checks. Panics when the duration is out of bounds.

source

pub fn minutes(minutes: i64) -> Duration

Makes a new Duration with given number of minutes. Equivalent to Duration::seconds(minutes * 60) with overflow checks. Panics when the duration is out of bounds.

source

pub fn seconds(seconds: i64) -> Duration

Makes a new Duration with given number of seconds. Panics when the duration is more than i64::MAX milliseconds or less than i64::MIN milliseconds.

source

pub fn milliseconds(milliseconds: i64) -> Duration

Makes a new Duration with given number of milliseconds.

source

pub fn microseconds(microseconds: i64) -> Duration

Makes a new Duration with given number of microseconds.

source

pub fn nanoseconds(nanos: i64) -> Duration

Makes a new Duration with given number of nanoseconds.

source

pub fn span<F>(f: F) -> Durationwhere F: FnOnce(),

Runs a closure, returning the duration of time it took to run the closure.

source

pub fn num_weeks(&self) -> i64

Returns the total number of whole weeks in the duration.

source

pub fn num_days(&self) -> i64

Returns the total number of whole days in the duration.

source

pub fn num_hours(&self) -> i64

Returns the total number of whole hours in the duration.

source

pub fn num_minutes(&self) -> i64

Returns the total number of whole minutes in the duration.

source

pub fn num_seconds(&self) -> i64

Returns the total number of whole seconds in the duration.

source

pub fn num_milliseconds(&self) -> i64

Returns the total number of whole milliseconds in the duration,

source

pub fn num_microseconds(&self) -> Option<i64>

Returns the total number of whole microseconds in the duration, or None on overflow (exceeding 263 microseconds in either direction).

source

pub fn num_nanoseconds(&self) -> Option<i64>

Returns the total number of whole nanoseconds in the duration, or None on overflow (exceeding 263 nanoseconds in either direction).

source

pub fn checked_add(&self, rhs: &Duration) -> Option<Duration>

Add two durations, returning None if overflow occurred.

source

pub fn checked_sub(&self, rhs: &Duration) -> Option<Duration>

Subtract two durations, returning None if overflow occurred.

source

pub fn min_value() -> Duration

The minimum possible Duration: i64::MIN milliseconds.

source

pub fn max_value() -> Duration

The maximum possible Duration: i64::MAX milliseconds.

source

pub fn zero() -> Duration

A duration where the stored seconds and nanoseconds are equal to zero.

source

pub fn is_zero(&self) -> bool

Returns true if the duration equals Duration::zero().

source

pub fn from_std(duration: StdDuration) -> Result<Duration, OutOfRangeError>

Creates a time::Duration object from std::time::Duration

This function errors when original duration is larger than the maximum value supported for this type.

source

pub fn to_std(&self) -> Result<StdDuration, OutOfRangeError>

Creates a std::time::Duration object from time::Duration

This function errors when duration is less than zero. As standard library implementation is limited to non-negative values.

Trait Implementations§

source§

impl Add<Duration> for Duration

§

type Output = Duration

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<Duration> for SteadyTime

§

type Output = SteadyTime

The resulting type after applying the + operator.
source§

fn add(self, other: Duration) -> SteadyTime

Performs the + operation. Read more
source§

impl Add<Duration> for Timespec

§

type Output = Timespec

The resulting type after applying the + operator.
source§

fn add(self, other: Duration) -> Timespec

Performs the + operation. Read more
source§

impl Add<Duration> for Tm

source§

fn add(self, other: Duration) -> Tm

The resulting Tm is in UTC.

§

type Output = Tm

The resulting type after applying the + operator.
source§

impl Clone for Duration

source§

fn clone(&self) -> Duration

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Duration

source§

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

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

impl Display for Duration

source§

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

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

impl Div<i32> for Duration

§

type Output = Duration

The resulting type after applying the / operator.
source§

fn div(self, rhs: i32) -> Duration

Performs the / operation. Read more
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 Mul<i32> for Duration

§

type Output = Duration

The resulting type after applying the * operator.
source§

fn mul(self, rhs: i32) -> Duration

Performs the * operation. Read more
source§

impl Neg for Duration

§

type Output = Duration

The resulting type after applying the - operator.
source§

fn neg(self) -> Duration

Performs the unary - operation. Read more
source§

impl Ord for Duration

source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

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

impl PartialEq<Duration> for Duration

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Duration> for Duration

source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Sub<Duration> for Duration

§

type Output = Duration

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<Duration> for SteadyTime

§

type Output = SteadyTime

The resulting type after applying the - operator.
source§

fn sub(self, other: Duration) -> SteadyTime

Performs the - operation. Read more
source§

impl Sub<Duration> for Timespec

§

type Output = Timespec

The resulting type after applying the - operator.
source§

fn sub(self, other: Duration) -> Timespec

Performs the - operation. Read more
source§

impl Sub<Duration> for Tm

source§

fn sub(self, other: Duration) -> Tm

The resulting Tm is in UTC.

§

type Output = Tm

The resulting type after applying the - operator.
source§

impl Copy for Duration

source§

impl Eq for Duration

source§

impl StructuralEq for Duration

source§

impl StructuralPartialEq for Duration

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.