human-repr
Generate beautiful human representations of bytes, durations and even throughputs!
What it does
This easily generate human-readable descriptions directly on primitive numbers, of several kinds:
- counts: which get SI prefixes: "k", "M", "G", "T", "P", "E", "Z", "Y";
- durations: with support for nanoseconds, millis, µs, secs, and even HH:MM:SS;
- throughputs: which get, in addition to SI prefixes, support for /day, /hour, /month, and /sec!!
They work on the following Rust primitive types: u8, u16, u32, u64, u128, usize, f32, f64, i8, i16, i32, i64, i128, isize.
The entity they refer to is configurable, so you can send "B" for bytes, or "it" for iterations, or "errors", etc.
Bytes have dedicated methods for convenience.
And it is blazingly fast, taking only ~80 ns to generate, and well-tested.
You can, for example:
use HumanRepr;
// counts (bytes or anything)
assert_eq!;
assert_eq!;
// durations
assert_eq!;
assert_eq!;
assert_eq!;
// throughputs (bytes or anything)
assert_eq!;
assert_eq!;
assert_eq!;
How to use it
Add this dependency to your Cargo.toml file:
= "0"
Use the trait:
use HumanRepr;
That's it! You can now call on any number:
;
;
;
;
;
Changelog
- 0.1.1 Jun 01, 2022: include readme
- 0.1.0 Jun 01, 2022: first release
License
This software is licensed under the MIT License. See the LICENSE file in the top distribution directory for the full license text.
Maintaining an open source project is hard and time-consuming, and I've put much ❤️ and effort into this.
If you've appreciated my work, you can back me up with a donation! Thank you 😊