pub type Duration = TimeDelta;Expand description
Alias of TimeDelta.
Aliased Type§
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 const fn subsec_nanos(&self) -> i32
pub const fn subsec_nanos(&self) -> i32
Returns the number of nanoseconds such that
subsec_nanos() + num_seconds() * NANOS_PER_SEC is the total number of
nanoseconds 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 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 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 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 zero() -> TimeDelta
pub const fn zero() -> TimeDelta
A TimeDelta where the stored seconds and nanoseconds are equal to zero.
Trait Implementations§
source§impl AddAssign<TimeDelta> for TimeDelta
impl AddAssign<TimeDelta> for TimeDelta
source§fn add_assign(&mut self, rhs: TimeDelta)
fn add_assign(&mut self, rhs: TimeDelta)
+= operation. Read moresource§impl Ord for TimeDelta
impl Ord for TimeDelta
source§impl PartialEq<TimeDelta> for TimeDelta
impl PartialEq<TimeDelta> for TimeDelta
source§impl PartialOrd<TimeDelta> for TimeDelta
impl PartialOrd<TimeDelta> for TimeDelta
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl SubAssign<TimeDelta> for TimeDelta
impl SubAssign<TimeDelta> for TimeDelta
source§fn sub_assign(&mut self, rhs: TimeDelta)
fn sub_assign(&mut self, rhs: TimeDelta)
-= operation. Read more