Function convert_byte_size_string::convert_to_bytes [−][src]
pub fn convert_to_bytes(string: &str) -> Result<u128, ConversionError>
Convert the provided string to a u128 value containing the number of bytes represented by the string. Implies the base to use based on the string, e.g. “KiB” uses base 2 and “KB” uses base 10.
Arguments
string
- The string to convert.
Returns
Err(ConversionError::InputInvalid)
if the input was invalid. The String may contain more information.Err(ConversionError::TooLarge)
if the
Example
use convert_byte_size_string::convert_to_bytes; assert_eq!(1024_u128, convert_to_bytes("1KiB").unwrap()); assert_eq!(1000_u128, convert_to_bytes("1KB").unwrap());