Skip to main content

parse_bytes

Function parse_bytes 

Source
pub fn parse_bytes(s: &str) -> BytesResult<u64>
Expand description

Parses a human-readable byte string into a number of bytes.

This method converts a string with units (e.g., “1.00 MiB”, “1KB”) into a u64 byte count. It supports both binary (KiB, MiB) and decimal (KB, MB) prefixes.

§Arguments

  • s - The string to parse

§Returns

Returns the number of bytes as a u64, or a BytesError if the string is invalid.

§Errors

§Example

use soar_utils::bytes::parse_bytes;

let bytes = parse_bytes("1.00 MiB").unwrap();

assert_eq!(bytes, 1024_u64.pow(2));