Pretty Bytes - Humanify Bytes for Easy Read

github crates.io docs.rs CI Build codecov

Rust library that takes a number that represent a byte and returns a string that is prettier to read for a human

Consumer of the Library

Install

sh cargo add pretty-bytes-rust

How to use?

Without Configuration Option

rust use pretty_bytes_rust::pretty_bytes; let r1 = pretty_bytes(1024 * 1024 * 5 + 512, None); assert_eq!(r1, "5.00 MB");

With Configuration Option - Specifying Decimal Precision

rust use pretty_bytes_rust::pretty_bytes; let result = pretty_bytes( 1024 * 1024 * 3, Some(PrettyBytesOptions { use_1024_instead_of_1000: Some(false), number_of_decimal: Some(3), remove_zero_decimal: Some(false), }), ); assert_eq!(result, "3.146 MB");

As a Developer of the Library

What to Install?

You need to install the right toolchain:

sh rustup toolchain install stable rustup default stable

To perform test coverage you need to install

sh cargo install grcov rustup component add llvm-tools-preview

To generate benchmark plots you need to install GnuPlot

```sh sudo apt update sudo apt install gnuplot

To confirm that it is properly installed:

which gnuplot ```

Tests

sh cargo test

Tests Coverage

You must install few components before running coverage:

sh cargo install grcov rustup component add llvm-tools-preview

Then, you can run:

sh ./coverage.sh

Further explanation in the Mozilla grcov website

Documentation

sh cargo doc --open

Benchmark

sh cargo bench

Publishing

sh cargo login cargo publish --dry-run cargo publish