Skip to main content

DurationNanos

Struct DurationNanos 

Source
pub struct DurationNanos(/* private fields */);
Expand description

Represents an unsigned duration in nanoseconds.

Implementations§

Source§

impl DurationNanos

Source

pub const ZERO: Self

A duration of zero nanoseconds.

Source

pub const MAX: Self

The maximum duration representable by this type.

Source

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

Creates a duration from an exact nanosecond count.

Source

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

Creates a duration from a number of whole microseconds.

§Panics

Panics if the result exceeds DurationNanos::MAX.

Source

pub const fn try_from_micros( micros: u64, ) -> Result<Self, DurationNanosOutOfRangeError>

Creates a duration from a number of whole microseconds.

§Errors

Returns an error if the result exceeds DurationNanos::MAX.

Source

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

Creates a duration from a number of whole milliseconds.

§Panics

Panics if the result exceeds DurationNanos::MAX.

Source

pub const fn try_from_millis( millis: u64, ) -> Result<Self, DurationNanosOutOfRangeError>

Creates a duration from a number of whole milliseconds.

§Errors

Returns an error if the result exceeds DurationNanos::MAX.

Source

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

Creates a duration from a number of whole seconds.

§Panics

Panics if the result exceeds DurationNanos::MAX.

Source

pub const fn try_from_secs( secs: u64, ) -> Result<Self, DurationNanosOutOfRangeError>

Creates a duration from a number of whole seconds.

§Errors

Returns an error if the result exceeds DurationNanos::MAX.

Source

pub const fn from_mins(mins: u64) -> Self

Creates a duration from a number of whole minutes.

§Panics

Panics if the result exceeds DurationNanos::MAX.

Source

pub const fn try_from_mins( mins: u64, ) -> Result<Self, DurationNanosOutOfRangeError>

Creates a duration from a number of whole minutes.

§Errors

Returns an error if the result exceeds DurationNanos::MAX.

Source

pub const fn from_hours(hours: u64) -> Self

Creates a duration from a number of whole hours.

§Panics

Panics if the result exceeds DurationNanos::MAX.

Source

pub const fn try_from_hours( hours: u64, ) -> Result<Self, DurationNanosOutOfRangeError>

Creates a duration from a number of whole hours.

§Errors

Returns an error if the result exceeds DurationNanos::MAX.

Source

pub const fn from_days(days: u64) -> Self

Creates a duration from a number of whole days.

§Panics

Panics if the result exceeds DurationNanos::MAX.

Source

pub const fn try_from_days( days: u64, ) -> Result<Self, DurationNanosOutOfRangeError>

Creates a duration from a number of whole days.

§Errors

Returns an error if the result exceeds DurationNanos::MAX.

Source

pub const fn is_zero(&self) -> bool

Returns true if the duration is zero.

Source

pub const fn as_u64(&self) -> u64

Returns the exact duration in nanoseconds as u64.

Source

pub const fn as_micros(&self) -> u64

Returns the total duration in whole microseconds.

Source

pub const fn as_millis(&self) -> u64

Returns the total duration in whole milliseconds.

Source

pub const fn as_secs(&self) -> u64

Returns the total duration in whole seconds.

Source

pub const fn as_secs_f64(&self) -> f64

Returns the total duration in seconds as f64.

Source

pub const fn as_mins(&self) -> u64

Returns the total duration in whole minutes.

Source

pub const fn as_hours(&self) -> u64

Returns the total duration in whole hours.

Source

pub const fn as_days(&self) -> u64

Returns the total duration in whole 24-hour days.

Source

pub const fn subsec_millis(&self) -> u64

Returns the fractional part of this duration in whole milliseconds.

Source

pub const fn subsec_micros(&self) -> u64

Returns the fractional part of this duration in whole microseconds.

Source

pub const fn subsec_nanos(&self) -> u64

Returns the fractional part of this duration in nanoseconds.

Source

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

Returns Some(self + rhs) or None if the addition would overflow.

Source

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

Returns Some(self - rhs) or None if the subtraction would underflow.

Source

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

Adds rhs, saturating at DurationNanos::MAX.

Source

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

Subtracts rhs, saturating at zero.

Source

pub const fn checked_mul(self, rhs: u64) -> Option<Self>

Returns Some(self * rhs) or None if the multiplication would overflow.

Source

pub const fn saturating_mul(self, rhs: u64) -> Self

Multiplies by rhs, saturating at DurationNanos::MAX.

Source

pub const fn checked_div(self, rhs: u64) -> Option<Self>

Returns Some(self / rhs) or None if rhs is zero.

Trait Implementations§

Source§

impl Add for DurationNanos

Adds two DurationNanos values.

§Panics

Panics if the result exceeds DurationNanos::MAX. Use DurationNanos::checked_add or DurationNanos::saturating_add for explicit overflow handling.

Source§

type Output = DurationNanos

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<DurationNanos> for UnixNanos

Adds a duration to a timestamp.

§Panics

Panics on overflow. Use UnixNanos::checked_add or UnixNanos::saturating_add for explicit overflow handling.

Source§

type Output = UnixNanos

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl AddAssign for DurationNanos

Add-assigns a duration.

§Panics

Panics if the result exceeds DurationNanos::MAX.

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl AddAssign<DurationNanos> for UnixNanos

Add-assigns a duration to UnixNanos.

§Panics

Panics on overflow. This is intentional fail-fast behavior for timestamp arithmetic.

Source§

fn add_assign(&mut self, rhs: DurationNanos)

Performs the += operation. Read more
Source§

impl Clone for DurationNanos

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 DurationNanos

Source§

impl Debug for DurationNanos

Source§

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

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

impl Default for DurationNanos

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for DurationNanos

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for DurationNanos

Source§

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

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

impl Div<u64> for DurationNanos

Divides a duration by an unsigned scalar.

§Panics

Panics if rhs is zero. Use DurationNanos::checked_div when the divisor may be zero.

Source§

type Output = DurationNanos

The resulting type after applying the / operator.
Source§

fn div(self, rhs: u64) -> Self::Output

Performs the / operation. Read more
Source§

impl DivAssign<u64> for DurationNanos

Divide-assigns a duration by an unsigned scalar.

§Panics

Panics if rhs is zero.

Source§

fn div_assign(&mut self, rhs: u64)

Performs the /= operation. Read more
Source§

impl Eq for DurationNanos

Source§

impl From<DurationNanos> for Duration

Source§

fn from(value: DurationNanos) -> Self

Converts to this type from the input type.
Source§

impl From<DurationNanos> for SignedDuration

Source§

fn from(value: DurationNanos) -> Self

Converts to this type from the input type.
Source§

impl Hash for DurationNanos

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<u64> for DurationNanos

Multiplies a duration by an unsigned scalar.

§Panics

Panics if the result exceeds DurationNanos::MAX. Use DurationNanos::checked_mul or DurationNanos::saturating_mul for explicit overflow handling.

Source§

type Output = DurationNanos

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: u64) -> Self::Output

Performs the * operation. Read more
Source§

impl MulAssign<u64> for DurationNanos

Multiply-assigns a duration by an unsigned scalar.

§Panics

Panics if the result exceeds DurationNanos::MAX.

Source§

fn mul_assign(&mut self, rhs: u64)

Performs the *= operation. Read more
Source§

impl Ord for DurationNanos

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 DurationNanos

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 DurationNanos

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 Serialize for DurationNanos

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for DurationNanos

Source§

impl Sub for DurationNanos

Subtracts one DurationNanos value from another.

§Panics

Panics if rhs exceeds self. Use DurationNanos::checked_sub or DurationNanos::saturating_sub for explicit underflow handling.

Source§

type Output = DurationNanos

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<DurationNanos> for UnixNanos

Subtracts a duration from a timestamp.

§Panics

Panics on underflow. Use UnixNanos::checked_sub or UnixNanos::saturating_sub for explicit underflow handling.

Source§

type Output = UnixNanos

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign for DurationNanos

Sub-assigns a duration.

§Panics

Panics if rhs exceeds self.

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl SubAssign<DurationNanos> for UnixNanos

Sub-assigns a duration from UnixNanos.

§Panics

Panics on underflow. This is intentional fail-fast behavior for timestamp arithmetic.

Source§

fn sub_assign(&mut self, rhs: DurationNanos)

Performs the -= operation. Read more
Source§

impl TryFrom<Duration> for DurationNanos

Source§

type Error = TryFromIntError

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

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

Performs the conversion.
Source§

impl TryFrom<SignedDuration> for DurationNanos

Source§

type Error = TryFromIntError

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

fn try_from(value: SignedDuration) -> Result<Self, Self::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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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, !>

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

impl<T> Ungil for T
where T: Send,