#[non_exhaustive]pub enum FractionalUnit {
Hour,
Minute,
Second,
Millisecond,
Microsecond,
}
Expand description
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 (Non-exhaustive)§
This enum is marked as non-exhaustive
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§
Source§impl Clone for FractionalUnit
impl Clone for FractionalUnit
Source§fn clone(&self) -> FractionalUnit
fn clone(&self) -> FractionalUnit
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for FractionalUnit
impl Debug for FractionalUnit
Source§impl From<FractionalUnit> for Unit
impl From<FractionalUnit> for Unit
Source§fn from(u: FractionalUnit) -> Unit
fn from(u: FractionalUnit) -> Unit
impl Copy for FractionalUnit
Auto Trait Implementations§
impl Freeze for FractionalUnit
impl RefUnwindSafe for FractionalUnit
impl Send for FractionalUnit
impl Sync for FractionalUnit
impl Unpin for FractionalUnit
impl UnwindSafe for FractionalUnit
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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