struct FractionalPrinter {
integer: u64,
fraction: u32,
padding: u8,
precision: Option<u8>,
}Expand description
A printer for a fraction with an integer and fraction component.
This also includes the formatter for the integer component and the formatter for the fractional component.
Fields§
§integer: u64§fraction: u32§padding: u8§precision: Option<u8>Implementations§
Source§impl FractionalPrinter
impl FractionalPrinter
Sourcefn from_span_seconds(
span: &Span,
padding: u8,
precision: Option<u8>,
) -> FractionalPrinter
fn from_span_seconds( span: &Span, padding: u8, precision: Option<u8>, ) -> FractionalPrinter
Build a fractional printer for the Span given. This includes the ..
Callers must ensure that all units greater than FractionalUnit are
zero in the span given.
Note that the printer returned only prints a fractional component
if necessary. For example, if the fractional component is zero and
precision is None, or if precision is Some(0), then no fractional
component will be emitted.
Sourcefn from_duration_seconds(
dur: &Duration,
padding: u8,
precision: Option<u8>,
) -> FractionalPrinter
fn from_duration_seconds( dur: &Duration, padding: u8, precision: Option<u8>, ) -> FractionalPrinter
Like from_span_seconds, but for SignedDuration.
Sourcefn from_duration(
dur: &Duration,
unit: FractionalUnit,
padding: u8,
precision: Option<u8>,
) -> FractionalPrinter
fn from_duration( dur: &Duration, unit: FractionalUnit, padding: u8, precision: Option<u8>, ) -> FractionalPrinter
Like from_duration_seconds, but for any fractional unit.
Sourcefn is_plural(&self) -> bool
fn is_plural(&self) -> bool
Returns true if this integer/fraction should be considered plural when choosing what designator to use.
Sourcefn must_write_digits(&self) -> bool
fn must_write_digits(&self) -> bool
Returns true if and only if this printer must write some kind of number
when print is called.
The only case where this returns false is when both the integer and
fractional component are zero and the precision is fixed to a number
greater than zero.
Sourcefn will_write_digits(&self) -> bool
fn will_write_digits(&self) -> 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.
Sourcefn has_non_zero_fixed_precision(&self) -> bool
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.
Sourcefn has_zero_fixed_precision(&self) -> bool
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.
Sourcefn print(&self, bbuf: &mut BorrowedBuffer<'_>)
fn print(&self, bbuf: &mut BorrowedBuffer<'_>)
Prints the integer and optional fractional component.
This will always print the integer, even if it’s zero. Therefore, if the caller wants to omit printing zero, the caller should do their own conditional logic.