Struct num_runtime_fmt::NumFmt[][src]

pub struct NumFmt { /* fields omitted */ }

Formatter for numbers.

Implementations

impl NumFmt[src]

pub fn builder() -> Builder[src]

Create a Builder to customize the parameters of a NumFmt.

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

Parse a NumFmt instance from a format string.

See crate-level documentation for the grammar.

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

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.

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

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.

pub fn fill(&self) -> char[src]

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

pub fn align(&self) -> Align[src]

Desired alignment.

pub fn sign(&self) -> Sign[src]

Which signs are printed with the number.

pub fn hash(&self) -> bool[src]

Whether to print a base specification before the number.

pub fn zero(&self) -> bool[src]

Whether the zero formatter was used.

pub fn width(&self) -> usize[src]

Configured render width in bytes.

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

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.

pub fn base(&self) -> Base[src]

Configured output format.

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

Configured group separator.

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

Configured group size.

pub fn decimal_separator(&self) -> char[src]

Configured decimal separator.

Trait Implementations

impl Clone for NumFmt[src]

impl Debug for NumFmt[src]

impl Default for NumFmt[src]

impl Eq for NumFmt[src]

impl From<NumFmt> for Builder[src]

impl FromStr for NumFmt[src]

type Err = Error

The associated error which can be returned from parsing.

impl PartialEq<NumFmt> for NumFmt[src]

impl StructuralEq for NumFmt[src]

impl StructuralPartialEq for NumFmt[src]

Auto Trait Implementations

impl RefUnwindSafe for NumFmt

impl Send for NumFmt

impl Sync for NumFmt

impl Unpin for NumFmt

impl UnwindSafe for NumFmt

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.