Struct FractionalFormatter

Source
pub(crate) struct FractionalFormatter {
    precision: Option<u8>,
}
Expand description

A simple formatter for converting fractional components to ASCII byte strings.

We only support precision to 9 decimal places, which corresponds to nanosecond precision as a fractional second component.

Fields§

§precision: Option<u8>

Implementations§

Source§

impl FractionalFormatter

Source

pub(crate) const fn new() -> FractionalFormatter

Creates a new fractional formatter using the given precision settings.

Source

pub(crate) const fn format(&self, value: i64) -> Fractional

Format the given value using this configuration as a decimal ASCII fractional number.

Source

pub(crate) const fn precision( self, precision: Option<u8>, ) -> FractionalFormatter

Set the precision.

If the precision is greater than 9, then it is clamped to 9.

When the precision is not set, then it is automatically determined based on the value.

Source

pub(crate) fn will_write_digits(self, value: i64) -> bool

Returns true if and only if at least one digit will be written for the given value.

This is useful for callers that need to know whether to write a decimal separator, e.g., ., before the digits.

Source

pub(crate) fn has_non_zero_fixed_precision(self) -> bool

Returns true if and only if this formatter has an explicit non-zero precision setting.

This is useful for determining whether something like 0.000 needs to be written in the case of a precision=Some(3) setting and a zero value.

Source

pub(crate) fn has_zero_fixed_precision(self) -> bool

Returns true if and only if this formatter has fixed zero precision. That is, no matter what is given as input, a fraction is never written.

Trait Implementations§

Source§

impl Clone for FractionalFormatter

Source§

fn clone(&self) -> FractionalFormatter

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FractionalFormatter

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Copy for FractionalFormatter

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> CloneToUninit for T
where T: Clone,

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.