Expand description
File size formatting for human-readable output.
This module provides functions to format byte sizes into human-readable strings, supporting both binary (1024-based: KiB, MiB, GiB) and decimal (1000-based: KB, MB, GB) units.
§Examples
use rich_rust::filesize::{decimal, format_size, SizeUnit};
// Decimal (1000-based) formatting
assert_eq!(decimal(1_500_000), "1.5 MB");
assert_eq!(decimal(1_000), "1.0 kB");
// Binary (1024-based) formatting
use rich_rust::filesize::binary;
assert_eq!(binary(1_048_576), "1.0 MiB");
assert_eq!(binary(1_024), "1.0 KiB");
// Custom precision
use rich_rust::filesize::decimal_with_precision;
assert_eq!(decimal_with_precision(1_536_000, 2), "1.54 MB");Enums§
- Size
Unit - Size unit system to use for formatting.
Functions§
- binary
- Format a size in bytes to a human-readable string using binary (1024-based) units.
- binary_
speed - Format a transfer speed using binary (1024-based) units.
- binary_
with_ precision - Format a size in bytes to a human-readable string using binary (1024-based) units with custom precision.
- decimal
- Format a size in bytes to a human-readable string using decimal (1000-based) units.
- decimal_
speed - Format a transfer speed using decimal (1000-based) units.
- decimal_
with_ precision - Format a size in bytes to a human-readable string using decimal (1000-based) units with custom precision.
- format_
size - Format a size in bytes to a human-readable string.
- format_
speed - Format a transfer speed in bytes per second to a human-readable string.