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 TimeDelta
s, 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 TimeDelta
s, 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 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 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