pub trait DurationExt: From<Duration> {
    fn as_duration(&self) -> &Duration;

    fn to_chrono_duration(&self) -> Duration { ... }
    fn from_micros(ts: u64) -> Self { ... }
    fn parse_secs<Str>(ts: &Str) -> Result<Self, Error>
    where
        Str: AsRef<str> + ?Sized
, { ... } fn display_millis(&'me self) -> DurationDisplay<'me, Self, Millis> { ... } fn display_micros(&'me self) -> DurationDisplay<'me, Self, Micros> { ... } fn display_nanos(&'me self) -> DurationDisplay<'me, Self, Nanos> { ... } }
Expand description

Adds functionalities to the Duration type.

Required Methods

Retrieves the duration from Self.

Provided Methods

Retrieves the chrono duration from Self.

Creates a duration from a timestamp in microseconds.

Duration parser from an amount of seconds, seen as a float.

Examples
use base::prelude::time::{Duration, DurationExt};
let s_list = vec![
    ("320.74", Duration::new(320, 740_000_000)),
    ("703470.0074", Duration::new(703470, 7_400_000)),
    ("0.2", Duration::new(0, 200_000_000)),
    ("7.0", Duration::new(7, 0)),
    (".003", Duration::new(0, 3_000_000)),
    ("42", Duration::new(42, 0)),
];
for (s, exp) in s_list {
    let duration = Duration::parse_secs(s).unwrap();
    assert_eq! { duration, exp }
}

Pretty displayable version of a duration, millisecond precision.

Pretty displayable version of a duration, microsecond precision.

Pretty displayable version of a duration, nanosecond precision.

Implementors