[−][src]Struct humantime::Duration
A wrapper for duration that has FromStr implementation
This is useful if you want to use it somewhere where FromStr is
expected.
See parse_duration for the description of the format.
Example
use std::time::Duration; let x: Duration; x = "12h 5min 2ns".parse::<humantime::Duration>().unwrap().into(); assert_eq!(x, Duration::new(12*3600 + 5*60, 2))
Methods from Deref<Target = StdDuration>
pub const SECOND: Duration[src]
pub const MILLISECOND: Duration[src]
pub const MICROSECOND: Duration[src]
pub const NANOSECOND: Duration[src]
pub const fn as_secs(&self) -> u641.3.0[src]
Returns the number of whole seconds contained by this Duration.
The returned value does not include the fractional (nanosecond) part of the
duration, which can be obtained using subsec_nanos.
Examples
use std::time::Duration; let duration = Duration::new(5, 730023852); assert_eq!(duration.as_secs(), 5);
To determine the total number of seconds represented by the Duration,
use as_secs in combination with subsec_nanos:
use std::time::Duration; let duration = Duration::new(5, 730023852); assert_eq!(5.730023852, duration.as_secs() as f64 + duration.subsec_nanos() as f64 * 1e-9);
pub const fn subsec_millis(&self) -> u321.27.0[src]
Returns the fractional part of this Duration, in whole milliseconds.
This method does not return the length of the duration when represented by milliseconds. The returned number always represents a fractional portion of a second (i.e., it is less than one thousand).
Examples
use std::time::Duration; let duration = Duration::from_millis(5432); assert_eq!(duration.as_secs(), 5); assert_eq!(duration.subsec_millis(), 432);
pub const fn subsec_micros(&self) -> u321.27.0[src]
Returns the fractional part of this Duration, in whole microseconds.
This method does not return the length of the duration when represented by microseconds. The returned number always represents a fractional portion of a second (i.e., it is less than one million).
Examples
use std::time::Duration; let duration = Duration::from_micros(1_234_567); assert_eq!(duration.as_secs(), 1); assert_eq!(duration.subsec_micros(), 234_567);
pub const fn subsec_nanos(&self) -> u321.3.0[src]
Returns the fractional part of this Duration, in nanoseconds.
This method does not return the length of the duration when represented by nanoseconds. The returned number always represents a fractional portion of a second (i.e., it is less than one billion).
Examples
use std::time::Duration; let duration = Duration::from_millis(5010); assert_eq!(duration.as_secs(), 5); assert_eq!(duration.subsec_nanos(), 10_000_000);
pub const fn as_millis(&self) -> u1281.33.0[src]
Returns the total number of whole milliseconds contained by this Duration.
Examples
use std::time::Duration; let duration = Duration::new(5, 730023852); assert_eq!(duration.as_millis(), 5730);
pub const fn as_micros(&self) -> u1281.33.0[src]
Returns the total number of whole microseconds contained by this Duration.
Examples
use std::time::Duration; let duration = Duration::new(5, 730023852); assert_eq!(duration.as_micros(), 5730023);
pub const fn as_nanos(&self) -> u1281.33.0[src]
Returns the total number of nanoseconds contained by this Duration.
Examples
use std::time::Duration; let duration = Duration::new(5, 730023852); assert_eq!(duration.as_nanos(), 5730023852);
pub const fn as_float_secs(&self) -> f64[src]
duration_float)Returns the number of seconds contained by this Duration as f64.
The returned value does include the fractional (nanosecond) part of the duration.
Examples
#![feature(duration_float)] use std::time::Duration; let dur = Duration::new(2, 700_000_000); assert_eq!(dur.as_float_secs(), 2.7);
Trait Implementations
impl AsRef<Duration> for Duration[src]
fn as_ref(&self) -> &StdDuration[src]
impl Into<Duration> for Duration[src]
fn into(self) -> StdDuration[src]
impl From<Duration> for Duration[src]
fn from(dur: StdDuration) -> Duration[src]
impl PartialEq<Duration> for Duration[src]
impl Eq for Duration[src]
impl Copy for Duration[src]
impl Clone for Duration[src]
fn clone(&self) -> Duration[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl Deref for Duration[src]
type Target = StdDuration
The resulting type after dereferencing.
fn deref(&self) -> &StdDuration[src]
impl Display for Duration[src]
impl Debug for Duration[src]
impl FromStr for Duration[src]
type Err = Error
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Duration, Self::Err>[src]
impl Hash for Duration[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>, [src]
U: From<T>,
impl<T> From for T[src]
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
impl<T> ToString for T where
T: Display + ?Sized, [src]
T: Display + ?Sized,
impl<T, U> TryFrom for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T> Borrow for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,