Skip to main content

format_bytes

Function format_bytes 

Source
pub fn format_bytes(bytes: u64, precision: usize) -> String
Expand description

Formats a number of bytes into a human-readable string.

This method converts a byte count into a string with appropriate units (B, KiB, MiB, etc.) and a specified level of precision.

§Arguments

  • bytes - The number of bytes to format
  • precision - The number of decimal places to display

§Returns

A human-readable string representation of the byte count.

§Example

use soar_utils::bytes::format_bytes;

let bytes = 1024_u64.pow(2);
let formatted = format_bytes(bytes, 2);

assert_eq!(formatted, "1.00 MiB");