Struct floating_duration::TimeFormat [] [src]

pub struct TimeFormat<T: Borrow<Duration>>(pub T);

A formatting newtype for providing a Display implementation. This format is meant to be used for printing performance measurements.

Behaviour

  • secs > 0 => seconds with precision 3
  • secs > 0.001 => milliseconds with precision 3
  • secs > 0.000_001 => microseconds with precision 3
  • otherwise => nanoseconds

By default the duration is formatted using abbreviated units (e.g. 1.234ms). If the the format string is specified with the alternate flag {:#}, the duration is formatted using the full unit name instead (e.g. 1.234 milliseconds).

Examples

use std::time::Duration;
use floating_duration::TimeFormat;

let dur = Duration::new(0, 461_933);
let formatted = format!("{}", TimeFormat(dur));
assert_eq!(formatted, "461.933µs");
let alternate = format!("{:#}", TimeFormat(dur));
assert_eq!(alternate, "461.933 microseconds");

Trait Implementations

impl<T: Clone + Borrow<Duration>> Clone for TimeFormat<T>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T: Copy + Borrow<Duration>> Copy for TimeFormat<T>
[src]

impl<T: Debug + Borrow<Duration>> Debug for TimeFormat<T>
[src]

[src]

Formats the value using the given formatter. Read more

impl<T: Borrow<Duration>> Display for TimeFormat<T>
[src]

[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<T> Send for TimeFormat<T> where
    T: Send

impl<T> Sync for TimeFormat<T> where
    T: Sync