Enum FractionalUnit

#[non_exhaustive]
pub enum FractionalUnit

Configuration for SpanPrinter::fractional.

This controls what kind of fractional unit to use when printing a duration. The default, unless SpanPrinter::hours_minutes_seconds is enabled, is to not write any fractional numbers at all.

The fractional unit set refers to the smallest whole integer that can occur in a "friendly" formatted duration. If there are any non-zero units less than the fractional unit in the duration, then they are formatted as a fraction.

Example

This example shows how to write the same duration with different fractional settings:

use jiff::{fmt::friendly::{FractionalUnit, SpanPrinter}, SignedDuration};

let duration = SignedDuration::from_secs(3663);

let printer = SpanPrinter::new()
    .fractional(Some(FractionalUnit::Hour));
assert_eq!(printer.duration_to_string(&duration), "1.0175h");

let printer = SpanPrinter::new()
    .fractional(Some(FractionalUnit::Minute));
assert_eq!(printer.duration_to_string(&duration), "1h 1.05m");

let printer = SpanPrinter::new()
    .fractional(Some(FractionalUnit::Second));
assert_eq!(printer.duration_to_string(&duration), "1h 1m 3s");

Variants

Hour

The smallest whole integer unit allowed is hours.

WARNING: Since fractional units are limited to 9 decimal places, using this setting could result in precision loss.

Minute

The smallest whole integer unit allowed is minutes.

WARNING: Since fractional units are limited to 9 decimal places, using this setting could result in precision loss.

Second

The smallest whole integer unit allowed is seconds.

Millisecond

The smallest whole integer unit allowed is milliseconds.

Microsecond

The smallest whole integer unit allowed is microseconds.

Trait Implementations

impl Clone for FractionalUnit

fn clone(&self) -> FractionalUnit

impl Copy for FractionalUnit

impl Debug for FractionalUnit

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Auto Trait Implementations

impl Freeze for FractionalUnit

impl RefUnwindSafe for FractionalUnit

impl Send for FractionalUnit

impl Sync for FractionalUnit

impl Unpin for FractionalUnit

impl UnsafeUnpin for FractionalUnit

impl UnwindSafe for FractionalUnit

Blanket Implementations

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

impl<T> CloneToUninit for FractionalUnit where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for FractionalUnit

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for FractionalUnit where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

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

fn into(self) -> U

Calls U::from(self).

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

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

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

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

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