pub struct Formatter<const BASE: usize = 0, const DECIMALS: usize = 2> { /* private fields */ }Expand description
Entry point to the lib. Use this to handle your formatting needs.
Implementations§
Source§impl<const BASE: usize, const DECIMALS: usize> Formatter<BASE, DECIMALS>
impl<const BASE: usize, const DECIMALS: usize> Formatter<BASE, DECIMALS>
Sourcepub const fn new(units: &'static [&'static str]) -> Self
pub const fn new(units: &'static [&'static str]) -> Self
Create a new Formatter with given BASE, DECIMALS and units.
Sourcepub const fn with_separator(self, separator: &'static str) -> Self
pub const fn with_separator(self, separator: &'static str) -> Self
Set the separator between numbers and units.
Sourcepub const fn with_scales<const N_BASE: usize>(
self,
units: &'static [&'static str],
) -> Formatter<N_BASE, DECIMALS>
pub const fn with_scales<const N_BASE: usize>( self, units: &'static [&'static str], ) -> Formatter<N_BASE, DECIMALS>
Set scales, including base and the abbreviated number’s units.
Sourcepub const fn with_custom_unit(self, custom_unit: &'static str) -> Self
pub const fn with_custom_unit(self, custom_unit: &'static str) -> Self
Set custom unit attached after the abbreviated number’s unit.
Sourcepub const fn with_decimals<const N_DECIMALS: usize>(
self,
) -> Formatter<BASE, N_DECIMALS>
pub const fn with_decimals<const N_DECIMALS: usize>( self, ) -> Formatter<BASE, N_DECIMALS>
Set the decimal places to keep.
Sourcepub fn format_int(&self, number: impl Into<isize>) -> FormatResult<DECIMALS>
pub fn format_int(&self, number: impl Into<isize>) -> FormatResult<DECIMALS>
Formats the given number into a human-readable string using the
specified units and separator.
Sourcepub fn format_uint(&self, number: impl Into<usize>) -> FormatResult<DECIMALS>
pub fn format_uint(&self, number: impl Into<usize>) -> FormatResult<DECIMALS>
Formats the given number into a human-readable string using the
specified units and separator.
Sourcepub fn format_float(&self, number: f64) -> FormatResult<DECIMALS>
pub fn format_float(&self, number: f64) -> FormatResult<DECIMALS>
Formats the given number into a human-readable string using the
specified units and separator.
Sourcepub fn format(
&self,
integer: usize,
fraction: Option<f64>,
) -> FormatResult<DECIMALS>
pub fn format( &self, integer: usize, fraction: Option<f64>, ) -> FormatResult<DECIMALS>
Formats the given number into a human-readable string using the
specified units and separator.
We recommend that you use format_float or
format_int.
§Params
integer: the integer part of the number.- For float,
f32::truncorf64::truncmay helps you.
- For float,
fraction: the fractional part of the number.- For float,
f32::fractorf64::fractmay helps you. - For integer, leave it
None.
- For float,