Struct DecimalFormatter

Source
pub(crate) struct DecimalFormatter {
    force_sign: Option<bool>,
    minimum_digits: u8,
    padding_byte: u8,
}
Expand description

A simple formatter for converting i64 values to ASCII byte strings.

This avoids going through the formatting machinery which seems to substantially slow things down.

The itoa crate does the same thing as this formatter, but is a bit faster. We roll our own which is a bit slower, but gets us enough of a win to be satisfied with and with (almost) pure safe code.

By default, this only includes the sign if it’s negative. To always include the sign, set force_sign to true.

Fields§

§force_sign: Option<bool>§minimum_digits: u8§padding_byte: u8

Implementations§

Source§

impl DecimalFormatter

Source

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

Creates a new decimal formatter using the default configuration.

Source

pub(crate) const fn padding(self, digits: u8) -> DecimalFormatter

The minimum number of digits/padding that this number should be formatted with. If the number would have fewer digits than this, then it is padded out with the padding byte (which is zero by default) until the minimum is reached.

The minimum number of digits is capped at the maximum number of digits for an i64 value (which is 19).

Source

pub(crate) const fn padding_byte(self, byte: u8) -> DecimalFormatter

The padding byte to use when padding is set.

The default is 0.

Trait Implementations§

Source§

impl Clone for DecimalFormatter

Source§

fn clone(&self) -> DecimalFormatter

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 DecimalFormatter

Source§

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

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

impl Default for DecimalFormatter

Source§

fn default() -> DecimalFormatter

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

impl Copy for DecimalFormatter

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.