Formatter

Struct Formatter 

Source
pub struct Formatter<const N: usize = 0> { /* private fields */ }
Expand description

Formatter of numbers for human-readable output.

Implementations§

Source§

impl Formatter

Source

pub const BINARY: Formatter<9>

Binary units (Ki, Mi, Gi, Ti, Pi, Ei, Zi, Yi)

Source

pub const CHINESE: Formatter<9>

Chinese units (, 亿, , , , , , )

Source

pub const SI: Formatter<9>

Decimal units (K, M, G, T, P, E, Z, Y)

Source§

impl<const N: usize> Formatter<N>

Source

pub const fn custom(ranged_units: &'static [RangedUnit; N]) -> Option<Self>

Creates a custom formatter with the given ranged units.

§Invariants
  • The first ranged_unit.range_max is the base, the nth ranged_unit.range_max is the nth power of the first ranged_unit.range_max.
  • ranged_units SHOULD NOT be empty.
Source

pub const unsafe fn custom_unchecked( ranged_units: &'static [RangedUnit; N], ) -> Self

Source

pub const fn with_separator(self, separator: &'static str) -> Self

Sets the separator between numbers and units.

Source

pub const fn with_custom_unit(self, custom_unit: &'static str) -> Self

Set custom unit attached after the abbreviated number’s unit.

Source

pub fn format(&self, target: impl Humat) -> Formatted

Formats a number, with default 2 decimal places.

Any number type that implements the Humat trait is supported.

Source

pub fn format_fixed_dp<const DECIMAL_PLACES: usize>( &self, target: impl Humat, ) -> Formatted<DECIMAL_PLACES>

Formats a number, with fixed DECIMAL_PLACES.

Any number type that implements the Humat trait is supported.

Source§

impl<const N: usize> Formatter<N>

Source

pub const fn format_uint(&self, target: u128) -> Formatted

Formats an unsigned integer, with default 2 decimal places.

Source

pub const fn format_uint_fixed_dp<const DECIMAL_PLACES: usize>( &self, target: u128, ) -> Formatted<DECIMAL_PLACES>

Formats an unsigned integer, with fixed DECIMAL_PLACES.

Source

pub const fn format_int(&self, target: i128) -> Formatted

Formats a signed integer, with default 2 decimal places.

Source

pub const fn format_int_fixed_dp<const DECIMAL_PLACES: usize>( &self, target: i128, ) -> Formatted<DECIMAL_PLACES>

Formats a signed integer, with fixed DECIMAL_PLACES.

Source

pub const fn format_double(&self, target: f64) -> Formatted

Formats an f64, with default 2 decimal places.

Source

pub const fn format_double_fixed_dp<const DECIMAL_PLACES: usize>( &self, target: f64, ) -> Formatted<DECIMAL_PLACES>

Formats an f64, with fixed DECIMAL_PLACES.

Source§

impl<const N: usize> Formatter<N>

Source

pub const fn format_usize(&self, target: usize) -> Formatted

Formats usize, with default 2 decimal places.

Source

pub const fn format_usize_fixed_dp<const DECIMAL_PLACES: usize>( &self, target: usize, ) -> Formatted<DECIMAL_PLACES>

Formats usize, with fixed DECIMAL_PLACES.

Source

pub const fn format_u128(&self, target: u128) -> Formatted

Formats u128, with default 2 decimal places.

Source

pub const fn format_u128_fixed_dp<const DECIMAL_PLACES: usize>( &self, target: u128, ) -> Formatted<DECIMAL_PLACES>

Formats u128, with fixed DECIMAL_PLACES.

Source

pub const fn format_u64(&self, target: u64) -> Formatted

Formats u64, with default 2 decimal places.

Source

pub const fn format_u64_fixed_dp<const DECIMAL_PLACES: usize>( &self, target: u64, ) -> Formatted<DECIMAL_PLACES>

Formats u64, with fixed DECIMAL_PLACES.

Source

pub const fn format_u32(&self, target: u32) -> Formatted

Formats u32, with default 2 decimal places.

Source

pub const fn format_u32_fixed_dp<const DECIMAL_PLACES: usize>( &self, target: u32, ) -> Formatted<DECIMAL_PLACES>

Formats u32, with fixed DECIMAL_PLACES.

Source

pub const fn format_u16(&self, target: u16) -> Formatted

Formats u16, with default 2 decimal places.

Source

pub const fn format_u16_fixed_dp<const DECIMAL_PLACES: usize>( &self, target: u16, ) -> Formatted<DECIMAL_PLACES>

Formats u16, with fixed DECIMAL_PLACES.

Source

pub const fn format_u8(&self, target: u8) -> Formatted

Formats u8, with default 2 decimal places.

Source

pub const fn format_u8_fixed_dp<const DECIMAL_PLACES: usize>( &self, target: u8, ) -> Formatted<DECIMAL_PLACES>

Formats u8, with fixed DECIMAL_PLACES.

Source§

impl<const N: usize> Formatter<N>

Source

pub const fn format_isize(&self, target: isize) -> Formatted

Formats isize, with default 2 decimal places.

Source

pub const fn format_isize_fixed_dp<const DECIMAL_PLACES: usize>( &self, target: isize, ) -> Formatted<DECIMAL_PLACES>

Formats isize, with fixed DECIMAL_PLACES.

Source

pub const fn format_i128(&self, target: i128) -> Formatted

Formats i128, with default 2 decimal places.

Source

pub const fn format_i128_fixed_dp<const DECIMAL_PLACES: usize>( &self, target: i128, ) -> Formatted<DECIMAL_PLACES>

Formats i128, with fixed DECIMAL_PLACES.

Source

pub const fn format_i64(&self, target: i64) -> Formatted

Formats i64, with default 2 decimal places.

Source

pub const fn format_i64_fixed_dp<const DECIMAL_PLACES: usize>( &self, target: i64, ) -> Formatted<DECIMAL_PLACES>

Formats i64, with fixed DECIMAL_PLACES.

Source

pub const fn format_i32(&self, target: i32) -> Formatted

Formats i32, with default 2 decimal places.

Source

pub const fn format_i32_fixed_dp<const DECIMAL_PLACES: usize>( &self, target: i32, ) -> Formatted<DECIMAL_PLACES>

Formats i32, with fixed DECIMAL_PLACES.

Source

pub const fn format_i16(&self, target: i16) -> Formatted

Formats i16, with default 2 decimal places.

Source

pub const fn format_i16_fixed_dp<const DECIMAL_PLACES: usize>( &self, target: i16, ) -> Formatted<DECIMAL_PLACES>

Formats i16, with fixed DECIMAL_PLACES.

Source

pub const fn format_i8(&self, target: i8) -> Formatted

Formats i8, with default 2 decimal places.

Source

pub const fn format_i8_fixed_dp<const DECIMAL_PLACES: usize>( &self, target: i8, ) -> Formatted<DECIMAL_PLACES>

Formats i8, with fixed DECIMAL_PLACES.

Source§

impl<const N: usize> Formatter<N>

Source

pub const fn format_f64(&self, target: f64) -> Formatted

Formats f64, with default 2 decimal places.

Source

pub const fn format_f64_fixed_dp<const DECIMAL_PLACES: usize>( &self, target: f64, ) -> Formatted<DECIMAL_PLACES>

Formats f64, with fixed DECIMAL_PLACES.

Source

pub const fn format_f32(&self, target: f32) -> Formatted

Formats f32, with default 2 decimal places.

Source

pub const fn format_f32_fixed_dp<const DECIMAL_PLACES: usize>( &self, target: f32, ) -> Formatted<DECIMAL_PLACES>

Formats f32, with fixed DECIMAL_PLACES.

Trait Implementations§

Source§

impl<const N: usize> Clone for Formatter<N>

Source§

fn clone(&self) -> Formatter<N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for Formatter<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Copy for Formatter<N>

Auto Trait Implementations§

§

impl<const N: usize> Freeze for Formatter<N>

§

impl<const N: usize> RefUnwindSafe for Formatter<N>

§

impl<const N: usize> Send for Formatter<N>

§

impl<const N: usize> Sync for Formatter<N>

§

impl<const N: usize> Unpin for Formatter<N>

§

impl<const N: usize> UnwindSafe for Formatter<N>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.