human_bandwidth

Function parse_bandwidth

Source
pub fn parse_bandwidth(s: &str) -> Result<Bandwidth, Error>
Expand description

Parse bandwidth object 1Gbps 12Mbps 5bps

The bandwidth object is a concatenation of rate spans. Where each rate span is an integer number and a suffix. Supported suffixes:

  • bps, bit/s, b/s – bit per second
  • kbps, kbit/s, kb/s – kilobit per second
  • Mbps, Mbit/s, Mb/s – megabit per second
  • Gbps, Gbit/s, Gb/s – gigabit per second
  • Tbps, Tbit/s, Tb/s – terabit per second

§Examples

use bandwidth::Bandwidth;
use human_bandwidth::parse_bandwidth;

assert_eq!(parse_bandwidth("9Tbps 420Gbps"), Ok(Bandwidth::new(9420, 0)));
assert_eq!(parse_bandwidth("32Mbps"), Ok(Bandwidth::new(0, 32_000_000)));