pub struct NumFmt { /* private fields */ }Expand description
Formatter for numbers.
Implementations§
Source§impl NumFmt
impl NumFmt
Sourcepub fn from_str(s: &str) -> Result<Self, Error>
pub fn from_str(s: &str) -> Result<Self, Error>
Parse a NumFmt instance from a format string.
See crate-level documentation for the grammar.
Sourcepub fn fmt<N: Numeric>(&self, number: N) -> Result<String, Error>
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.
Sourcepub fn fmt_with<N: Numeric>(
&self,
number: N,
dynamic: Dynamic,
) -> Result<String, Error>
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.
Sourcepub fn fill(&self) -> char
pub fn fill(&self) -> char
char used to pad the extra space when the rendered number is smaller than the width.
Sourcepub fn precision(&self) -> Option<usize>
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.
Sourcepub fn decimal_separator(&self) -> char
pub fn decimal_separator(&self) -> char
Configured decimal separator.
Trait Implementations§
impl Eq for NumFmt
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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