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
impl FractionalFormatter
Sourcepub(crate) const fn new() -> FractionalFormatter
pub(crate) const fn new() -> FractionalFormatter
Creates a new fractional formatter using the given precision settings.
Sourcepub(crate) const fn format(&self, value: i64) -> Fractional
pub(crate) const fn format(&self, value: i64) -> Fractional
Format the given value using this configuration as a decimal ASCII fractional number.
Sourcepub(crate) const fn precision(
self,
precision: Option<u8>,
) -> FractionalFormatter
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.
Sourcepub(crate) fn will_write_digits(self, value: i64) -> bool
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.
Sourcepub(crate) fn has_non_zero_fixed_precision(self) -> bool
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.
Sourcepub(crate) fn has_zero_fixed_precision(self) -> bool
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
impl Clone for FractionalFormatter
Source§fn clone(&self) -> FractionalFormatter
fn clone(&self) -> FractionalFormatter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more