pub struct Humanizer { /* private fields */ }Expand description
A struct that can be used to humanize numbers with custom units.
Implementations§
Source§impl Humanizer
impl Humanizer
Sourcepub fn with_space_before_unit(self, space_before_unit: bool) -> Self
pub fn with_space_before_unit(self, space_before_unit: bool) -> Self
Sets whether or not to add a space before the unit (default: true).
Example: true -> “1 MB”, false -> “1MB”.
Sourcepub fn with_division_factor<F>(self, factor: F) -> Self
pub fn with_division_factor<F>(self, factor: F) -> Self
Sets the division factor between units (default: 1000.0).
Example: Use 1024.0 for binary prefixes (KiB, MiB, etc.).
§Panics
Panics if the division factor is less than or equal to 0.
Sourcepub fn format<U>(&self, value: U) -> String
pub fn format<U>(&self, value: U) -> String
Formats a number into a human readable string using the humanizer’s units.
§Example
use handy::human::Humanizer;
let humanizer = Humanizer::new(&["", "k", "m", "b", "t"]).with_space_before_unit(false);
assert_eq!(humanizer.format(123_456_789), "123m");§Arguments
value- The value to format.
§Returns
A human readable string using the humanizer’s units.
Sourcepub fn format_as_parts<U>(&self, value: U) -> (f64, &str)
pub fn format_as_parts<U>(&self, value: U) -> (f64, &str)
Formats a number into a human readable string using the humanizer’s units but returns the value and the unit.
§Example
use handy::human::Humanizer;
let humanizer = Humanizer::new(&["", "k", "m", "b", "t"]);
assert_eq!(humanizer.format_as_parts(123_456_789), (123.456789, "m"));§Arguments
value- The value to format.
§Returns
f64- The value.&str- The unit.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Humanizer
impl RefUnwindSafe for Humanizer
impl Send for Humanizer
impl Sync for Humanizer
impl Unpin for Humanizer
impl UnsafeUnpin for Humanizer
impl UnwindSafe for Humanizer
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
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>
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 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>
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