PrettySize, rust edition

crates.io docs.rs

A comprehensive file size crate for rust applications, meant to be light and effective. Includes utilities for human-readable formatting of file sizes as well as converting between different base-two and base-ten size units.

Features

PrettySize provides

Usage

Cargo.toml:

toml [dependencies] size = "0.1"

and in your code:

```rust extern crate size; use size::{Base, Size, Style};

fn main() { let bytecount = 42 * size::KiB; asserteq!(43_008, bytecount);

    let byte_count = Size::Kilobytes(42);
    assert_eq!(42__000, byte_count.bytes());

    // `Size` can take any numeric type you throw at it
    let byte_count2 = Size::Mebibytes(0.040055);
    assert_eq!(byte_count.bytes(), byte_count2.bytes());

    // And for those of you that haven't yet drunk the base-two Kool-Aid:
    let byte_count = Size::Kilobytes(42);
    assert_eq!(byte_count.bytes(), 42_000);

    println!("{}, I say!", byte_count);
    // prints "41 KiB, I say!"

    println!("{}, I meant!", byte_count.to_string(Base::Base10, Style::Abbreviated));
    // prints "42 KB, I meant!"

} ```

About

This project started off as a port of the PrettySize.NET library from C# to Rust. Like the C# edition of this project. Rust's richer enum types and powerful generics made implementing a custom Size generic over the number type without verbosity additionally possible.

PrettySize is written and maintained by Mahmoud Al-Qudsi of NeoSmart Technologies and released to the general public under the terms of the MIT public license.

To-Do

Pull requests are welcomed!