pub fn format_bandwidth(val: Bandwidth) -> FormattedBandwidthExpand description
Formats bandwidth into a human-readable string
Note: this format is guaranteed to have same value when using parse_bandwidth, but we can change some details of the exact composition of the value.
By default it will format the value with the largest possible unit in decimal form.
If you want to display integer values only, enable the display-integer feature.
ยงExamples
use bandwidth::Bandwidth;
use human_bandwidth::format_bandwidth;
// Enabling the `display-integer` feature will display integer values only
let val1 = Bandwidth::new(9420, 0);
assert_eq!(format_bandwidth(val1).to_string(), "9Tbps 420Gbps");
let val2 = Bandwidth::new(0, 32_000_000);
assert_eq!(format_bandwidth(val2).to_string(), "32Mbps");
// Disabling the `display-integer` feature will display decimal values
let val1 = Bandwidth::new(9420, 0);
assert_eq!(format_bandwidth(val1).to_string(), "9.42Tbps");
let val2 = Bandwidth::new(0, 32_000_000);
assert_eq!(format_bandwidth(val2).to_string(), "32Mbps");