Function humansize::format_size

source ·
pub fn format_size(
    input: impl ToF64 + Unsigned,
    options: impl AsRef<FormatSizeOptions>
) -> String
Examples found in repository?
examples/custom_options.rs (line 9)
4
5
6
7
8
9
10
fn main() {
    // Create a new FormatSizeOptions struct starting from one of the defaults
    let custom_options = FormatSizeOptions::from(DECIMAL).decimal_places(5);

    // Then use it
    println!("{}", format_size(3024usize, custom_options));
}
More examples
Hide additional examples
examples/sizes.rs (line 6)
5
6
7
8
9
10
11
12
13
14
15
16
fn main() {
    println!("{}", format_size(5456usize, BINARY));
    println!("{}", format_size(1024usize, DECIMAL));
    println!("{}", format_size(1000usize, WINDOWS));

    println!("{}", format_size(1_023_654_123_654_u64, BINARY));
    println!("{}", format_size(123456789usize, DECIMAL));
    println!("{}", format_size_i(-123456789, WINDOWS));

    println!("{}", SizeFormatter::new(1234u32, BINARY));
    println!("{}", ISizeFormatter::new(1234, BINARY));
}