pub struct Duration { /* private fields */ }
Expand description
ISO 8601 time duration with nanosecond precision. This also allows for the negative duration; see individual methods for details.
Implementations
sourceimpl Duration
impl Duration
sourcepub fn weeks(weeks: i64) -> Duration
pub fn weeks(weeks: i64) -> Duration
Makes a new Duration
with given number of weeks.
Equivalent to Duration::seconds(weeks * 7 * 24 * 60 * 60)
with overflow checks.
Panics when the duration is out of bounds.
sourcepub fn days(days: i64) -> Duration
pub fn days(days: i64) -> Duration
Makes a new Duration
with given number of days.
Equivalent to Duration::seconds(days * 24 * 60 * 60)
with overflow checks.
Panics when the duration is out of bounds.
sourcepub fn hours(hours: i64) -> Duration
pub fn hours(hours: i64) -> Duration
Makes a new Duration
with given number of hours.
Equivalent to Duration::seconds(hours * 60 * 60)
with overflow checks.
Panics when the duration is out of bounds.
sourcepub fn minutes(minutes: i64) -> Duration
pub fn minutes(minutes: i64) -> Duration
Makes a new Duration
with given number of minutes.
Equivalent to Duration::seconds(minutes * 60)
with overflow checks.
Panics when the duration is out of bounds.
sourcepub fn seconds(seconds: i64) -> Duration
pub fn seconds(seconds: i64) -> Duration
Makes a new Duration
with given number of seconds.
Panics when the duration is more than i64::MAX
milliseconds
or less than i64::MIN
milliseconds.
sourcepub fn milliseconds(milliseconds: i64) -> Duration
pub fn milliseconds(milliseconds: i64) -> Duration
Makes a new Duration
with given number of milliseconds.
sourcepub fn microseconds(microseconds: i64) -> Duration
pub fn microseconds(microseconds: i64) -> Duration
Makes a new Duration
with given number of microseconds.
sourcepub fn nanoseconds(nanos: i64) -> Duration
pub fn nanoseconds(nanos: i64) -> Duration
Makes a new Duration
with given number of nanoseconds.
sourcepub fn span<F>(f: F) -> Duration where
F: FnOnce(),
pub fn span<F>(f: F) -> Duration where
F: FnOnce(),
Runs a closure, returning the duration of time it took to run the closure.
sourcepub fn num_minutes(&self) -> i64
pub fn num_minutes(&self) -> i64
Returns the total number of whole minutes in the duration.
sourcepub fn num_seconds(&self) -> i64
pub fn num_seconds(&self) -> i64
Returns the total number of whole seconds in the duration.
sourcepub fn num_milliseconds(&self) -> i64
pub fn num_milliseconds(&self) -> i64
Returns the total number of whole milliseconds in the duration,
sourcepub fn num_microseconds(&self) -> Option<i64>
pub fn num_microseconds(&self) -> Option<i64>
Returns the total number of whole microseconds in the duration,
or None
on overflow (exceeding 263 microseconds in either direction).
sourcepub fn num_nanoseconds(&self) -> Option<i64>
pub fn num_nanoseconds(&self) -> Option<i64>
Returns the total number of whole nanoseconds in the duration,
or None
on overflow (exceeding 263 nanoseconds in either direction).
sourcepub fn checked_add(&self, rhs: &Duration) -> Option<Duration>
pub fn checked_add(&self, rhs: &Duration) -> Option<Duration>
Add two durations, returning None
if overflow occurred.
sourcepub fn checked_sub(&self, rhs: &Duration) -> Option<Duration>
pub fn checked_sub(&self, rhs: &Duration) -> Option<Duration>
Subtract two durations, returning None
if overflow occurred.
sourcepub fn zero() -> Duration
pub fn zero() -> Duration
A duration where the stored seconds and nanoseconds are equal to zero.
sourcepub fn from_std(duration: StdDuration) -> Result<Duration, OutOfRangeError>
pub fn from_std(duration: StdDuration) -> Result<Duration, OutOfRangeError>
Creates a time::Duration
object from std::time::Duration
This function errors when original duration is larger than the maximum value supported for this type.
sourcepub fn to_std(&self) -> Result<StdDuration, OutOfRangeError>
pub fn to_std(&self) -> Result<StdDuration, OutOfRangeError>
Creates a std::time::Duration
object from time::Duration
This function errors when duration is less than zero. As standard library implementation is limited to non-negative values.
Trait Implementations
sourceimpl Add<Duration> for SteadyTime
impl Add<Duration> for SteadyTime
type Output = SteadyTime
type Output = SteadyTime
The resulting type after applying the +
operator.
sourcefn add(self, other: Duration) -> SteadyTime
fn add(self, other: Duration) -> SteadyTime
Performs the +
operation. Read more
sourceimpl Ord for Duration
impl Ord for Duration
sourceimpl PartialOrd<Duration> for Duration
impl PartialOrd<Duration> for Duration
sourcefn partial_cmp(&self, other: &Duration) -> Option<Ordering>
fn partial_cmp(&self, other: &Duration) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl Sub<Duration> for SteadyTime
impl Sub<Duration> for SteadyTime
type Output = SteadyTime
type Output = SteadyTime
The resulting type after applying the -
operator.
sourcefn sub(self, other: Duration) -> SteadyTime
fn sub(self, other: Duration) -> SteadyTime
Performs the -
operation. Read more
impl Copy for Duration
impl Eq for Duration
impl StructuralEq for Duration
impl StructuralPartialEq for Duration
Auto Trait Implementations
impl RefUnwindSafe for Duration
impl Send for Duration
impl Sync for Duration
impl Unpin for Duration
impl UnwindSafe for Duration
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more