pretty-bytes-rust 0.1.0

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

Pretty Bytes - Humanify Bytes for Easy Read

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

cargo add pretty-bytes-rust

How to use?

Without Configuration Option

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

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:

rustup toolchain install stable
rustup default stable

To perform test coverage you need to install

cargo install grcov
rustup component add llvm-tools-preview

To generate benchmark plots you need to install GnuPlot

sudo apt update
sudo apt install gnuplot

# To confirm that it is properly installed:
which gnuplot

Tests

cargo test

Tests Coverage

You must install few components before running coverage:

cargo install grcov
rustup component add llvm-tools-preview

Then, you can run:

./coverage.sh

Further explanation in the Mozilla grcov website

Documentation

cargo doc --open

Benchmark

cargo bench

Publishing

cargo login
cargo publish --dry-run
cargo publish