pub type Duration = TimeDelta;Expand description
Alias of TimeDelta.
Aliased Type§
pub struct Duration { /* private fields */ }Implementations
Source§impl TimeDelta
impl TimeDelta
Sourcepub const fn new(secs: i64, nanos: u32) -> Option<TimeDelta>
pub const fn new(secs: i64, nanos: u32) -> Option<TimeDelta>
Makes a new TimeDelta with given number of seconds and nanoseconds.
§Errors
Returns None when the duration is out of bounds, or if nanos ≥ 1,000,000,000.
Sourcepub const fn weeks(weeks: i64) -> TimeDelta
pub const fn weeks(weeks: i64) -> TimeDelta
Makes a new TimeDelta with the given number of weeks.
Equivalent to TimeDelta::seconds(weeks * 7 * 24 * 60 * 60) with
overflow checks.
§Panics
Panics when the duration is out of bounds.
Sourcepub const fn try_weeks(weeks: i64) -> Option<TimeDelta>
pub const fn try_weeks(weeks: i64) -> Option<TimeDelta>
Makes a new TimeDelta with the given number of weeks.
Equivalent to TimeDelta::try_seconds(weeks * 7 * 24 * 60 * 60) with
overflow checks.
§Errors
Returns None when the TimeDelta would be out of bounds.
Sourcepub const fn days(days: i64) -> TimeDelta
pub const fn days(days: i64) -> TimeDelta
Makes a new TimeDelta with the given number of days.
Equivalent to TimeDelta::seconds(days * 24 * 60 * 60) with overflow
checks.
§Panics
Panics when the TimeDelta would be out of bounds.
Sourcepub const fn try_days(days: i64) -> Option<TimeDelta>
pub const fn try_days(days: i64) -> Option<TimeDelta>
Makes a new TimeDelta with the given number of days.
Equivalent to TimeDelta::try_seconds(days * 24 * 60 * 60) with overflow
checks.
§Errors
Returns None when the TimeDelta would be out of bounds.
Sourcepub const fn hours(hours: i64) -> TimeDelta
pub const fn hours(hours: i64) -> TimeDelta
Makes a new TimeDelta with the given number of hours.
Equivalent to TimeDelta::seconds(hours * 60 * 60) with overflow checks.
§Panics
Panics when the TimeDelta would be out of bounds.
Sourcepub const fn try_hours(hours: i64) -> Option<TimeDelta>
pub const fn try_hours(hours: i64) -> Option<TimeDelta>
Makes a new TimeDelta with the given number of hours.
Equivalent to TimeDelta::try_seconds(hours * 60 * 60) with overflow checks.
§Errors
Returns None when the TimeDelta would be out of bounds.
Sourcepub const fn minutes(minutes: i64) -> TimeDelta
pub const fn minutes(minutes: i64) -> TimeDelta
Makes a new TimeDelta with the given number of minutes.
Equivalent to TimeDelta::seconds(minutes * 60) with overflow checks.
§Panics
Panics when the TimeDelta would be out of bounds.
Sourcepub const fn try_minutes(minutes: i64) -> Option<TimeDelta>
pub const fn try_minutes(minutes: i64) -> Option<TimeDelta>
Makes a new TimeDelta with the given number of minutes.
Equivalent to TimeDelta::try_seconds(minutes * 60) with overflow checks.
§Errors
Returns None when the TimeDelta would be out of bounds.
Sourcepub const fn seconds(seconds: i64) -> TimeDelta
pub const fn seconds(seconds: i64) -> TimeDelta
Makes a new TimeDelta with the given number of seconds.
§Panics
Panics when seconds is more than i64::MAX / 1_000 or less than -i64::MAX / 1_000
(in this context, this is the same as i64::MIN / 1_000 due to rounding).
Sourcepub const fn try_seconds(seconds: i64) -> Option<TimeDelta>
pub const fn try_seconds(seconds: i64) -> Option<TimeDelta>
Makes a new TimeDelta with the given number of seconds.
§Errors
Returns None when seconds is more than i64::MAX / 1_000 or less than
-i64::MAX / 1_000 (in this context, this is the same as i64::MIN / 1_000 due to
rounding).
Sourcepub const fn milliseconds(milliseconds: i64) -> TimeDelta
pub const fn milliseconds(milliseconds: i64) -> TimeDelta
Makes a new TimeDelta with the given number of milliseconds.
§Panics
Panics when the TimeDelta would be out of bounds, i.e. when milliseconds is more than
i64::MAX or less than -i64::MAX. Notably, this is not the same as i64::MIN.
Sourcepub const fn try_milliseconds(milliseconds: i64) -> Option<TimeDelta>
pub const fn try_milliseconds(milliseconds: i64) -> Option<TimeDelta>
Makes a new TimeDelta with the given number of milliseconds.
§Errors
Returns None the TimeDelta would be out of bounds, i.e. when milliseconds is more
than i64::MAX or less than -i64::MAX. Notably, this is not the same as i64::MIN.
Sourcepub const fn microseconds(microseconds: i64) -> TimeDelta
pub const fn microseconds(microseconds: i64) -> TimeDelta
Makes a new TimeDelta with the given number of microseconds.
The number of microseconds acceptable by this constructor is less than
the total number that can actually be stored in a TimeDelta, so it is
not possible to specify a value that would be out of bounds. This
function is therefore infallible.
Sourcepub const fn nanoseconds(nanos: i64) -> TimeDelta
pub const fn nanoseconds(nanos: i64) -> TimeDelta
Makes a new TimeDelta with the given number of nanoseconds.
The number of nanoseconds acceptable by this constructor is less than
the total number that can actually be stored in a TimeDelta, so it is
not possible to specify a value that would be out of bounds. This
function is therefore infallible.
Sourcepub const fn num_minutes(&self) -> i64
pub const fn num_minutes(&self) -> i64
Returns the total number of whole minutes in the TimeDelta.
Sourcepub const fn num_seconds(&self) -> i64
pub const fn num_seconds(&self) -> i64
Returns the total number of whole seconds in the TimeDelta.
Sourcepub fn as_seconds_f64(self) -> f64
pub fn as_seconds_f64(self) -> f64
Returns the fractional number of seconds in the TimeDelta.
Sourcepub fn as_seconds_f32(self) -> f32
pub fn as_seconds_f32(self) -> f32
Returns the fractional number of seconds in the TimeDelta.
Sourcepub const fn num_milliseconds(&self) -> i64
pub const fn num_milliseconds(&self) -> i64
Returns the total number of whole milliseconds in the TimeDelta.
Sourcepub const fn subsec_millis(&self) -> i32
pub const fn subsec_millis(&self) -> i32
Returns the number of milliseconds in the fractional part of the duration.
This is the number of milliseconds such that
subsec_millis() + num_seconds() * 1_000 is the truncated number of
milliseconds in the duration.
Sourcepub const fn num_microseconds(&self) -> Option<i64>
pub const fn num_microseconds(&self) -> Option<i64>
Returns the total number of whole microseconds in the TimeDelta,
or None on overflow (exceeding 2^63 microseconds in either direction).
Sourcepub const fn subsec_micros(&self) -> i32
pub const fn subsec_micros(&self) -> i32
Returns the number of microseconds in the fractional part of the duration.
This is the number of microseconds such that
subsec_micros() + num_seconds() * 1_000_000 is the truncated number of
microseconds in the duration.
Sourcepub const fn num_nanoseconds(&self) -> Option<i64>
pub const fn num_nanoseconds(&self) -> Option<i64>
Returns the total number of whole nanoseconds in the TimeDelta,
or None on overflow (exceeding 2^63 nanoseconds in either direction).
Sourcepub const fn subsec_nanos(&self) -> i32
pub const fn subsec_nanos(&self) -> i32
Returns the number of nanoseconds in the fractional part of the duration.
This is the number of nanoseconds such that
subsec_nanos() + num_seconds() * 1_000_000_000 is the total number of
nanoseconds in the TimeDelta.
Sourcepub const fn checked_add(&self, rhs: &TimeDelta) -> Option<TimeDelta>
pub const fn checked_add(&self, rhs: &TimeDelta) -> Option<TimeDelta>
Add two TimeDeltas, returning None if overflow occurred.
Sourcepub const fn checked_sub(&self, rhs: &TimeDelta) -> Option<TimeDelta>
pub const fn checked_sub(&self, rhs: &TimeDelta) -> Option<TimeDelta>
Subtract two TimeDeltas, returning None if overflow occurred.
Sourcepub const fn checked_mul(&self, rhs: i32) -> Option<TimeDelta>
pub const fn checked_mul(&self, rhs: i32) -> Option<TimeDelta>
Multiply a TimeDelta with a i32, returning None if overflow occurred.
Sourcepub const fn checked_div(&self, rhs: i32) -> Option<TimeDelta>
pub const fn checked_div(&self, rhs: i32) -> Option<TimeDelta>
Divide a TimeDelta with a i32, returning None if dividing by 0.
Sourcepub const fn abs(&self) -> TimeDelta
pub const fn abs(&self) -> TimeDelta
Returns the TimeDelta as an absolute (non-negative) value.
Sourcepub const fn min_value() -> TimeDelta
👎Deprecated since 0.4.39: Use TimeDelta::MIN instead
pub const fn min_value() -> TimeDelta
TimeDelta::MIN insteadThe minimum possible TimeDelta: -i64::MAX milliseconds.
Sourcepub const fn max_value() -> TimeDelta
👎Deprecated since 0.4.39: Use TimeDelta::MAX instead
pub const fn max_value() -> TimeDelta
TimeDelta::MAX insteadThe maximum possible TimeDelta: i64::MAX milliseconds.
Sourcepub const fn zero() -> TimeDelta
pub const fn zero() -> TimeDelta
A TimeDelta where the stored seconds and nanoseconds are equal to zero.
Trait Implementations
Source§impl AddAssign for TimeDelta
impl AddAssign for TimeDelta
Source§fn add_assign(&mut self, rhs: TimeDelta)
fn add_assign(&mut self, rhs: TimeDelta)
+= operation. Read moreSource§impl<'de> Deserialize<'de> for TimeDelta
impl<'de> Deserialize<'de> for TimeDelta
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl Ord for TimeDelta
impl Ord for TimeDelta
Source§impl PartialOrd for TimeDelta
impl PartialOrd for TimeDelta
Source§impl SubAssign for TimeDelta
impl SubAssign for TimeDelta
Source§fn sub_assign(&mut self, rhs: TimeDelta)
fn sub_assign(&mut self, rhs: TimeDelta)
-= operation. Read more