Function bytefmt::parse

source ·
pub fn parse<S: Into<String>>(str: S) -> Result<u64, &'static str>
Expand description

Parse given string to bytes count

Examples

assert_eq!(bytefmt::parse("123").unwrap(), 123);
assert_eq!(bytefmt::parse("1.23 B").unwrap(), 1);
assert_eq!(bytefmt::parse("1.23 KB").unwrap(), 1_230);
assert_eq!(bytefmt::parse("1.23 MB").unwrap(), 1_230_000);
assert_eq!(bytefmt::parse("1.23 GB").unwrap(), 1_230_000_000);
assert_eq!(bytefmt::parse("1.23 TB").unwrap(), 1_230_000_000_000);
assert_eq!(bytefmt::parse("1.23 PB").unwrap(), 1_230_000_000_000_000);
assert_eq!(bytefmt::parse("1.23 KiB").unwrap(), 1_259);
assert_eq!(bytefmt::parse("1.23 MiB").unwrap(), 1_289_748);
assert_eq!(bytefmt::parse("1.23 GiB").unwrap(), 1_320_702_443);
assert_eq!(bytefmt::parse("1.23 TiB").unwrap(), 1_352_399_302_164);
assert_eq!(bytefmt::parse("1.23 PiB").unwrap(), 1_384_856_885_416_427);