PrettySize, rust edition
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
- definitions for the base-two and base-ten file size units defined as
pub constin thesizenamespace, available both in abbreviated and unabridged forms (i.e.size::EiBandsize::EXBIBYTEorsize::GBandsize::GIGABYTE), - a
Unitenum that defines the base-two and base-ten units, - a
Size<T>enum that can be used to hold a typed file size (e.g.let size = Size::Terabytes(4);), - an
std::Displayimpl forSizeto display sizes in a human-readable format, - a
Size.to_string(..)method that allows you to specify the base of the human-readable units and their style (smart, abbreviated, or full and their lowercase variants)
Usage
Cargo.toml:
[]
= "0.1"
and in your code:
extern crate size;
use ;
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
- Providing a
FromStrimpl to parse file sizes, - Implementing direct unit-to-unit conversion,
- Implementing format specifiers to allow using
format!(..)directly to obtain output in the desired base and style, - Bypassing double conversion when formatting
Size<T>for integralTtypes,
Pull requests are welcomed!