Skip to main content

Duration

Struct Duration 

Source
pub struct Duration { /* private fields */ }
Expand description

Signed duration, represented as seconds and normalized nanoseconds.

Implementations§

Source§

impl Duration

Source

pub const ZERO: Duration

Source

pub fn new(seconds: i64, nanos: i32) -> Result<Duration, Error>

Creates a duration from seconds and a nanosecond adjustment.

Source

pub fn from_normalized(seconds: i64, nanos: u32) -> Result<Duration, Error>

Creates a duration from normalized seconds and nanoseconds.

Source

pub fn from_parts(seconds: i64, nanos: i64) -> Result<Duration, Error>

Creates a duration from seconds and an arbitrary nanosecond adjustment.

Source

pub const fn from_secs(seconds: i64) -> Duration

Creates a duration from whole seconds.

Source

pub fn from_minutes(minutes: i64) -> Result<Duration, Error>

Creates a duration from minutes.

Source

pub fn from_hours(hours: i64) -> Result<Duration, Error>

Creates a duration from hours.

Source

pub fn from_days(days: i64) -> Result<Duration, Error>

Creates a duration from days.

Source

pub fn from_millis(millis: i64) -> Duration

Creates a duration from milliseconds.

Source

pub fn from_micros(micros: i64) -> Duration

Creates a duration from microseconds.

Source

pub fn from_nanos(nanos: i128) -> Result<Duration, Error>

Creates a duration from nanoseconds.

Source

pub const fn seconds(self) -> i64

Returns the normalized seconds component.

Source

pub const fn subsec_nanos(self) -> u32

Returns the normalized nanosecond component.

Source

pub const fn is_zero(self) -> bool

Returns whether this duration is zero.

Source

pub const fn is_positive(self) -> bool

Returns whether this duration is greater than zero.

Source

pub const fn is_negative(self) -> bool

Returns whether this duration is less than zero.

Source

pub fn to_millis(self) -> Result<i64, Error>

Returns whole milliseconds, rounded down for sub-millisecond values.

Source

pub fn to_micros(self) -> Result<i64, Error>

Returns whole microseconds, rounded down for sub-microsecond values.

Source

pub fn to_nanos(self) -> i128

Returns nanoseconds.

Source

pub fn checked_add(self, other: Duration) -> Result<Duration, Error>

Adds two durations.

Source

pub fn checked_sub(self, other: Duration) -> Result<Duration, Error>

Subtracts other from this duration.

Source

pub fn checked_neg(self) -> Result<Duration, Error>

Negates this duration.

Source

pub fn abs(self) -> Result<Duration, Error>

Returns the absolute duration.

Trait Implementations§

Source§

impl Clone for Duration

Source§

fn clone(&self) -> Duration

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<(), Error>

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

impl Default for Duration

Source§

fn default() -> Duration

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

impl Eq for Duration

Source§

impl Hash for Duration

Source§

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

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: &Duration) -> 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§

impl PartialEq for Duration

Source§

fn eq(&self, other: &Duration) -> 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: &Duration) -> 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 Serializer for Duration

Source§

type Target = Duration

Source§

fn write_data( value: &Duration, context: &mut WriteContext<'_>, ) -> Result<(), Error>

Write the target body only.
Source§

fn read_data(context: &mut ReadContext<'_>) -> Result<Duration, Error>

Read the target body only.
Source§

fn default_value(_: &mut ReadContext<'_>) -> Result<Duration, Error>

Construct a target for a null or missing local value.
Source§

fn read_arc_any( context: &mut ReadContext<'_>, ) -> Result<Arc<dyn Any + Send + Sync>, Error>

Read directly into the final owner for sync dynamic carriers.
Source§

impl StructuralPartialEq for Duration

Source§

impl TryFrom<Duration> for Duration

Source§

type Error = Error

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

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

Performs the conversion.

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> ForyObject for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

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> ToOwned for T
where T: Clone,

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 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.