parse_size

Function parse_size

Source
pub fn parse_size<T: AsRef<[u8]>>(src: T) -> Result<u64, Error>
Expand description

Parses the string input into the number of bytes it represents using the default configuration.

Equivalent to calling Config::parse_size() with the default configuration (Config::new()).

§Examples

use parse_size::{parse_size, Error};

assert_eq!(parse_size("10 KB"), Ok(10000));
assert_eq!(parse_size("20000"), Ok(20000));
assert_eq!(parse_size("0.2 MiB"), Ok(209715));
assert_eq!(parse_size("^_^"), Err(Error::InvalidDigit));

§Errors

Returns an Error if the input has invalid digits or the result exceeded 264−1.