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: u8Implementations§
Source§impl DecimalFormatter
impl DecimalFormatter
Sourcepub(crate) const fn new() -> DecimalFormatter
pub(crate) const fn new() -> DecimalFormatter
Creates a new decimal formatter using the default configuration.
Sourcepub(crate) const fn format_signed(&self, value: i64) -> Decimal
pub(crate) const fn format_signed(&self, value: i64) -> Decimal
Format the given value using this configuration as a signed decimal ASCII number.
Sourcepub(crate) const fn format_unsigned(&self, value: u64) -> Decimal
pub(crate) const fn format_unsigned(&self, value: u64) -> Decimal
Format the given value using this configuration as an unsigned decimal ASCII number.
Sourcepub(crate) const fn padding(self, digits: u8) -> DecimalFormatter
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 (19) or a u64 value (20).
Sourcepub(crate) const fn padding_byte(self, byte: u8) -> DecimalFormatter
pub(crate) const fn padding_byte(self, byte: u8) -> DecimalFormatter
The padding byte to use when padding is set.
The default is 0.
Sourceconst fn get_signed_minimum_digits(&self) -> u8
const fn get_signed_minimum_digits(&self) -> u8
Returns the minimum number of digits for a signed value.
Sourceconst fn get_unsigned_minimum_digits(&self) -> u8
const fn get_unsigned_minimum_digits(&self) -> u8
Returns the minimum number of digits for an unsigned value.
Trait Implementations§
Source§impl Clone for DecimalFormatter
impl Clone for DecimalFormatter
Source§fn clone(&self) -> DecimalFormatter
fn clone(&self) -> DecimalFormatter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more