Struct NumFmt

Source
pub struct NumFmt { /* private fields */ }
Expand description

Formatter for numbers.

Implementations§

Source§

impl NumFmt

Source

pub fn builder() -> Builder

Create a Builder to customize the parameters of a NumFmt.

Source

pub fn from_str(s: &str) -> Result<Self, Error>

Parse a NumFmt instance from a format string.

See crate-level documentation for the grammar.

Source

pub fn fmt<N: Numeric>(&self, number: N) -> Result<String, Error>

Format the provided number according to this configuration.

Will return None in the event that the configured format is incompatible with the number provided. This is most often the case when the number is not an integer but an integer format such as b, o, or x is configured.

Source

pub fn fmt_with<N: Numeric>( &self, number: N, dynamic: Dynamic, ) -> Result<String, Error>

Format the provided number according to this configuration and dynamic parameters.

Note that dynamic parameters always override the formatter’s parameters:

let fmt = NumFmt::from_str("#04x_2").unwrap();
assert_eq!(fmt.fmt(0).unwrap(), "0x00");
assert_eq!(fmt.fmt_with(0, Dynamic::width(7)).unwrap(), "0x00_00");

Will return None in the event that the configured format is incompatible with the number provided. This is most often the case when the number is not an integer but an integer format such as b, o, or x is configured.

Source

pub fn fill(&self) -> char

char used to pad the extra space when the rendered number is smaller than the width.

Source

pub fn align(&self) -> Align

Desired alignment.

Source

pub fn sign(&self) -> Sign

Which signs are printed with the number.

Source

pub fn hash(&self) -> bool

Whether to print a base specification before the number.

Source

pub fn zero(&self) -> bool

Whether the zero formatter was used.

Source

pub fn width(&self) -> usize

Configured render width in bytes.

Source

pub fn precision(&self) -> Option<usize>

Configured post-decimal precision in bytes.

Precision will pad or truncate as required if set. If unset, passes through as many digits past the decimal as the underlying type naturally returns.

Source

pub fn base(&self) -> Base

Configured output format.

Source

pub fn separator(&self) -> Option<char>

Configured group separator.

Source

pub fn spacing(&self) -> Option<usize>

Configured group size.

Source

pub fn decimal_separator(&self) -> char

Configured decimal separator.

Trait Implementations§

Source§

impl Clone for NumFmt

Source§

fn clone(&self) -> NumFmt

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 Debug for NumFmt

Source§

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

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

impl Default for NumFmt

Source§

fn default() -> NumFmt

Returns the “default value” for a type. Read more
Source§

impl From<NumFmt> for Builder

Source§

fn from(_: NumFmt) -> Self

Converts to this type from the input type.
Source§

impl FromStr for NumFmt

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for NumFmt

Source§

fn eq(&self, other: &NumFmt) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for NumFmt

Source§

impl StructuralPartialEq for NumFmt

Auto Trait Implementations§

§

impl Freeze for NumFmt

§

impl RefUnwindSafe for NumFmt

§

impl Send for NumFmt

§

impl Sync for NumFmt

§

impl Unpin for NumFmt

§

impl UnwindSafe for NumFmt

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.