DurationFormatOptions

Struct DurationFormatOptions 

Source
pub struct DurationFormatOptions { /* private fields */ }
Expand description

Format a duration as e.g. 3.2s or 1h 42m.

Implementations§

Source§

impl DurationFormatOptions

Source

pub fn with_only_seconds(self, only_seconds: bool) -> Self

If true, format 63 seconds as 63s. If false, format it as 1m3s

Source

pub fn with_always_sign(self, always_sign: bool) -> Self

Always show the sign, even if it is positive (+).

Source

pub fn with_min_decimals(self, min_decimals: usize) -> Self

Number of sub-second decimals to at least show.

So 3 means at least millisecond accuracy, etc.

Supported values: 0,1,3,6,9

Source

pub fn with_max_decimals(self, max_decimals: usize) -> Self

Number of sub-second to show at most.

So 6 means at most microsecond accuracy, etc.

Supported values: 0,1,3,6,9

Source

pub fn round_towards_zero(self) -> Self

When we hit with_max_decimals, round towards zero.

Source

pub fn round_to_closest(self) -> Self

When we hit with_max_decimals, round to closest.

Source

pub fn format_nanos(self, ns: i64) -> String

Formats nanoseconds in a pretty way, as specific.

This function is NOT optimized for performance (and does many small allocations).

Trait Implementations§

Source§

impl Default for DurationFormatOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.