pub struct SiFormatted<T> { /* private fields */ }Expand description
This is a number wrapped for formatting.
The with_* methods can be used to customize display.
Implementations§
Source§impl<T> SiFormatted<T>
impl<T> SiFormatted<T>
Sourcepub fn with_precision(self, significant_digits: usize) -> Self
pub fn with_precision(self, significant_digits: usize) -> Self
The number of significant digits to display.
Unlike the precision for std::fmt, this includes digits before the decimal point.
use si_format::Formattable;
assert_eq!(1234567.si_format().with_precision(5).to_string(),"1.234_6M");Currently, this must be at least 3.
Sourcepub fn with_shift(self, shift: i8) -> Self
pub fn with_shift(self, shift: i8) -> Self
Multiply formatted value by a power of ten.
The input number x is formatted as if it were x*10^shift.
This allows formatting of fractional quantities using integers:
use si_format::Formattable;
assert_eq!(format!("{}s",(22u64).si_format().with_shift(-3)),"22.0ms");No actual multiplication is performed, the multiplied value need not be representable as T.
Trait Implementations§
Source§impl<T: FormatImpl> Debug for SiFormatted<T>
impl<T: FormatImpl> Debug for SiFormatted<T>
Auto Trait Implementations§
impl<T> Freeze for SiFormatted<T>where
T: Freeze,
impl<T> RefUnwindSafe for SiFormatted<T>where
T: RefUnwindSafe,
impl<T> Send for SiFormatted<T>where
T: Send,
impl<T> Sync for SiFormatted<T>where
T: Sync,
impl<T> Unpin for SiFormatted<T>where
T: Unpin,
impl<T> UnwindSafe for SiFormatted<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more