pub fn parse_binary_bandwidth(s: &str) -> Result<Bandwidth, Error>Expand description
Parse bandwidth object 1GiBps 12MiBps 5Bps or 1.012000005GiBps
Unlike parse_bandwidth, this method expect bandwidth to
be written in binary prefix system
The bandwidth object is a concatenation of rate spans. Where each rate span is an number and a suffix. Supported suffixes:
Bps,Byte/s,B/s,ops, ’o/s` – Byte per secondkiBps,kiByte/s,kiB/s,kiops, ’kio/s` – kibiByte per secondMiBps,MiByte/s,MiB/s,Miops, ’Mio/s` – mebiByte per secondGiBps,GiByte/s,GiB/s,Giops, ’Gio/s` – gibiByte per secondTiBps,TiByte/s,TiB/s,Tiops, ’Tio/s` – tebiByte per second
While the number can be integer or decimal, the fractional part less than 1Bps will always be rounded to the closest (ties away from zero).
§Examples
use bandwidth::Bandwidth;
use human_bandwidth::binary_system::parse_binary_bandwidth;
assert_eq!(parse_binary_bandwidth("9TiBps 420GiBps"), Ok(Bandwidth::new(82772, 609728512)));
assert_eq!(parse_binary_bandwidth("4MiBps"), Ok(Bandwidth::new(0, 4 * 8 * 1024 * 1024)));
assert_eq!(parse_binary_bandwidth("150.024kiBps"),
Ok(Bandwidth::new(0, (150.024 * 1024_f64).round() as u32 * 8)));
// The fractional part less than 1Bps will always be ignored
assert_eq!(parse_binary_bandwidth("150.02456kiBps"),
Ok(Bandwidth::new(0, (150.02456 * 1024_f64).round() as u32 * 8)));