FractionalPrinter

Struct FractionalPrinter 

Source
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

Source

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.

Source

fn from_duration_seconds( dur: &Duration, padding: u8, precision: Option<u8>, ) -> FractionalPrinter

Like from_span_seconds, but for SignedDuration.

Source

fn from_duration( dur: &Duration, unit: FractionalUnit, padding: u8, precision: Option<u8>, ) -> FractionalPrinter

Like from_duration_seconds, but for any fractional unit.

Source

fn is_zero(&self) -> bool

Returns true if both the integer and fractional component are zero.

Source

fn is_plural(&self) -> bool

Returns true if this integer/fraction should be considered plural when choosing what designator to use.

Source

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.

Source

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.

Source

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

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.

Source

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.

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> 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, 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.