xarxa

Crates

git

Versions

default

Flavors

Skip to main content

Duration

Struct Duration 

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

A relative amount of time, in milliseconds.

A duration is at most Duration::MAX, about 12.4 days. Constructors and arithmetic saturate at it. This keeps every timer the stack sets well within the range where an Instant compares correctly.

Implementations§

Source§

impl Duration

Source

pub const ZERO: Duration

A duration of zero time.

Source

pub const MAX: Duration

The longest duration: 230 ms, about 12.4 days.

Source

pub const fn from_millis(millis: u32) -> Duration

Create a new Duration from a number of milliseconds.

Saturates at Duration::MAX.

Source

pub const fn from_secs(secs: u32) -> Duration

Create a new Duration from a number of seconds.

Saturates at Duration::MAX.

Source

pub fn from_secs_f64(secs: f64) -> Duration

Create a new Duration from a number of seconds, as an f64.

The fraction below one millisecond is truncated. Saturates at Duration::MAX.

§Panics

Panics if secs is negative or NaN.

Source

pub fn from_secs_f32(secs: f32) -> Duration

Create a new Duration from a number of seconds, as an f32.

The fraction below one millisecond is truncated. Saturates at Duration::MAX.

§Panics

Panics if secs is negative or NaN.

Source

pub const fn is_zero(&self) -> bool

Whether this is Duration::ZERO.

Source

pub const fn as_secs(&self) -> u32

The number of whole seconds in this Duration.

Source

pub const fn as_millis(&self) -> u32

The number of milliseconds in this Duration.

Source

pub const fn subsec_millis(&self) -> u32

The number of milliseconds past as_secs.

Always less than 1000.

Source

pub fn as_secs_f64(&self) -> f64

This Duration as a number of seconds, as an f64.

Source

pub fn as_secs_f32(&self) -> f32

This Duration as a number of seconds, as an f32.

Source

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

self + rhs, or None if it is longer than Duration::MAX.

Source

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

self - rhs, or None if rhs is longer than self.

Source

pub const fn checked_mul(&self, rhs: u32) -> Option<Duration>

self * rhs, or None if it is longer than Duration::MAX.

Source

pub const fn checked_div(&self, rhs: u32) -> Option<Duration>

self / rhs, or None if rhs is zero.

Source

pub const fn div_ceil(&self, rhs: u32) -> Duration

self / rhs, rounded up to the next millisecond.

Panics if rhs is zero.

Source

pub const fn saturating_add(&self, rhs: Duration) -> Duration

self + rhs, saturating at Duration::MAX.

Source

pub const fn saturating_sub(&self, rhs: Duration) -> Duration

self - rhs, saturating at Duration::ZERO.

Source

pub const fn saturating_mul(&self, rhs: u32) -> Duration

self * rhs, saturating at Duration::MAX.

Source

pub const fn abs_diff(&self, other: Duration) -> Duration

The absolute difference between self and other.

Source

pub fn mul_f64(&self, rhs: f64) -> Duration

self multiplied by rhs.

Saturates at Duration::MAX.

§Panics

Panics if the result is negative or NaN.

Source

pub fn mul_f32(&self, rhs: f32) -> Duration

self multiplied by rhs.

Saturates at Duration::MAX.

§Panics

Panics if the result is negative or NaN.

Source

pub fn div_f64(&self, rhs: f64) -> Duration

self divided by rhs.

Saturates at Duration::MAX.

§Panics

Panics if the result is negative or NaN.

Source

pub fn div_f32(&self, rhs: f32) -> Duration

self divided by rhs.

Saturates at Duration::MAX.

§Panics

Panics if the result is negative or NaN.

Source

pub fn div_duration_f64(&self, rhs: Duration) -> f64

The ratio of self to rhs.

Source

pub fn div_duration_f32(&self, rhs: Duration) -> f32

The ratio of self to rhs.

Trait Implementations§

Source§

impl Add for Duration

Source§

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

Saturates at Duration::MAX.

Source§

type Output = Duration

The resulting type after applying the + operator.
Source§

impl Add<Duration> for Instant

Source§

type Output = Instant

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl AddAssign for Duration

Source§

fn add_assign(&mut self, rhs: Duration)

Performs the += operation. Read more
Source§

impl AddAssign<Duration> for Instant

Source§

fn add_assign(&mut self, rhs: Duration)

Performs the += operation. Read more
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

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

Source§

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

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

impl Div<u32> for Duration

Source§

type Output = Duration

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl DivAssign<u32> for Duration

Source§

fn div_assign(&mut self, rhs: u32)

Performs the /= operation. Read more
Source§

impl Eq for Duration

Source§

impl From<Duration> for Duration

Source§

fn from(other: Duration) -> Duration

Truncates below one millisecond, and saturates at Duration::MAX.

Source§

impl From<Duration> for Duration

Source§

fn from(val: Duration) -> Self

Converts to this type from the input type.
Source§

impl Mul<Duration> for u32

Source§

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

Saturates at Duration::MAX.

Source§

type Output = Duration

The resulting type after applying the * operator.
Source§

impl Mul<u32> for Duration

Source§

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

Saturates at Duration::MAX.

Source§

type Output = Duration

The resulting type after applying the * operator.
Source§

impl MulAssign<u32> for Duration

Source§

fn mul_assign(&mut self, rhs: u32)

Performs the *= 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 (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 StructuralPartialEq for Duration

Source§

impl Sub for Duration

Source§

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 Instant

Source§

type Output = Instant

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign for Duration

Source§

fn sub_assign(&mut self, rhs: Duration)

Performs the -= operation. Read more
Source§

impl SubAssign<Duration> for Instant

Source§

fn sub_assign(&mut self, rhs: Duration)

Performs the -= operation. Read more

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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, <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.