pub fn pretty_bytes(bytes: u64, options: Option<PrettyBytesOptions>) -> String
Expand description
pretty_bytes main function that convert bytes into a pretty format that is easier to read for a humain
§Arguments
The first argument is the number of bytes to transform
The second argument is the option. Can be set to None
to use the default of 2 decimals and 1024 bytes per unit
§Examples
§Example without option (default)
use pretty_bytes_rust::pretty_bytes;
let r1 = pretty_bytes(1024 * 1024 * 5 + 50000, None);
assert_eq!(r1, "5.05 Mbit");
§Example with options to false
use pretty_bytes_rust::pretty_bytes;
use pretty_bytes_rust::PrettyBytesOptions;
let r2 = pretty_bytes(1024 * 1024 * 9 + 123, Some(PrettyBytesOptions {
use_1024_instead_of_1000: Some(false),
number_of_decimal: Some(3),
remove_zero_decimal: Some(false)
}));
assert_eq!(r2, "9.437 MB");
§Example with options to true
use pretty_bytes_rust::pretty_bytes;
use pretty_bytes_rust::PrettyBytesOptions;
let r2 = pretty_bytes(1024 * 1024 * 9 + 123, Some(PrettyBytesOptions {
use_1024_instead_of_1000: Some(true),
number_of_decimal: Some(3),
remove_zero_decimal: Some(true)
}));
assert_eq!(r2, "9.000 Mbit");