Rust library that takes a number that represent a byte and returns a string that is prettier to read for a human
sh
cargo add pretty-bytes-rust
rust
use pretty_bytes_rust::pretty_bytes;
let r1 = pretty_bytes(1024 * 1024 * 5 + 512, None);
assert_eq!(r1, "5.00 MB");
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");
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
which gnuplot ```
sh
cargo test
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
sh
cargo doc --open
sh
cargo bench
sh
cargo login
cargo publish --dry-run
cargo publish