pub struct Duration { /* private fields */ }Expand description
A relative amount of time.
Implementations§
Source§impl Duration
impl Duration
Sourcepub const fn from_micros(micros: u64) -> Duration
pub const fn from_micros(micros: u64) -> Duration
Create a new Duration from a number of microseconds.
Sourcepub const fn from_millis(millis: u64) -> Duration
pub const fn from_millis(millis: u64) -> Duration
Create a new Duration from a number of milliseconds.
Sourcepub fn from_secs_f64(secs: f64) -> Duration
pub fn from_secs_f64(secs: f64) -> Duration
Create a new Duration from a number of seconds, as an f64.
The fraction below one microsecond is truncated.
§Panics
Panics if secs is negative, NaN, or too large to represent.
Sourcepub fn from_secs_f32(secs: f32) -> Duration
pub fn from_secs_f32(secs: f32) -> Duration
Create a new Duration from a number of seconds, as an f32.
The fraction below one microsecond is truncated.
§Panics
Panics if secs is negative, NaN, or too large to represent.
Sourcepub const fn is_zero(&self) -> bool
pub const fn is_zero(&self) -> bool
Whether this is Duration::ZERO.
Sourcepub const fn subsec_millis(&self) -> u32
pub const fn subsec_millis(&self) -> u32
The number of milliseconds past as_secs.
Always less than 1000.
Sourcepub const fn subsec_micros(&self) -> u32
pub const fn subsec_micros(&self) -> u32
The number of microseconds past as_secs.
Always less than 1000000.
Sourcepub const fn subsec_nanos(&self) -> u32
pub const fn subsec_nanos(&self) -> u32
The number of nanoseconds past as_secs.
Always less than 1000000000, and always a whole number of microseconds.
Sourcepub fn as_secs_f64(&self) -> f64
pub fn as_secs_f64(&self) -> f64
This Duration as a number of seconds, as an f64.
Sourcepub fn as_secs_f32(&self) -> f32
pub fn as_secs_f32(&self) -> f32
This Duration as a number of seconds, as an f32.
Sourcepub const fn checked_add(&self, rhs: Duration) -> Option<Duration>
pub const fn checked_add(&self, rhs: Duration) -> Option<Duration>
self + rhs, or None on overflow.
Sourcepub const fn checked_sub(&self, rhs: Duration) -> Option<Duration>
pub const fn checked_sub(&self, rhs: Duration) -> Option<Duration>
self - rhs, or None if rhs is longer than self.
Sourcepub const fn checked_mul(&self, rhs: u32) -> Option<Duration>
pub const fn checked_mul(&self, rhs: u32) -> Option<Duration>
self * rhs, or None on overflow.
Sourcepub const fn checked_div(&self, rhs: u32) -> Option<Duration>
pub const fn checked_div(&self, rhs: u32) -> Option<Duration>
self / rhs, or None if rhs is zero.
Sourcepub const fn saturating_add(&self, rhs: Duration) -> Duration
pub const fn saturating_add(&self, rhs: Duration) -> Duration
self + rhs, saturating at Duration::MAX.
Sourcepub const fn saturating_sub(&self, rhs: Duration) -> Duration
pub const fn saturating_sub(&self, rhs: Duration) -> Duration
self - rhs, saturating at Duration::ZERO.
Sourcepub const fn saturating_mul(&self, rhs: u32) -> Duration
pub const fn saturating_mul(&self, rhs: u32) -> Duration
self * rhs, saturating at Duration::MAX.
Sourcepub const fn abs_diff(&self, other: Duration) -> Duration
pub const fn abs_diff(&self, other: Duration) -> Duration
The absolute difference between self and other.
Sourcepub fn div_duration_f64(&self, rhs: Duration) -> f64
pub fn div_duration_f64(&self, rhs: Duration) -> f64
The ratio of self to rhs.
Sourcepub fn div_duration_f32(&self, rhs: Duration) -> f32
pub fn div_duration_f32(&self, rhs: Duration) -> f32
The ratio of self to rhs.
Trait Implementations§
Source§impl AddAssign for Duration
impl AddAssign for Duration
Source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+= operation. Read moreSource§impl AddAssign<Duration> for Instant
impl AddAssign<Duration> for Instant
Source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+= operation. Read moreimpl Copy for Duration
Source§impl DivAssign<u32> for Duration
impl DivAssign<u32> for Duration
Source§fn div_assign(&mut self, rhs: u32)
fn div_assign(&mut self, rhs: u32)
/= operation. Read moreimpl Eq for Duration
Source§impl MulAssign<u32> for Duration
impl MulAssign<u32> for Duration
Source§fn mul_assign(&mut self, rhs: u32)
fn mul_assign(&mut self, rhs: u32)
*= operation. Read more