bytefmt

Crates.iobytefmt
lib.rsbytefmt
version0.1.7
sourcesrc
created_at2018-11-08 12:08:54.493312
updated_at2018-11-08 23:36:49.101192
descriptionan utility to parse byte string into bytes count and vice versa.
homepagehttps://github.com/emsifa/bytefmt
repositoryhttps://github.com/emsifa/bytefmt
max_upload_size
id95471
size18,284
Muhammad Syifa (emsifa)

documentation

https://docs.rs/bytefmt/

README

bytefmt

bytefmt on travis bytefmt on crates.io bytefmt on docs.rs

Bytefmt is Rust utility to parse byte string into bytes count and vice versa.

Installation

Put bytefmt to your dependencies in Cargo.toml file:

[dependencies]
bytefmt = "0.1.7"

Usage Examples

extern crate bytefmt;

fn main() {
    let input = "1.23 MB";

    // Parse string into bytes
    let bytes: u64 = bytefmt::parse(input).unwrap();
    assert_eq!(bytes, 1_230_000);

    // Format bytes into string
    let bytes_str = bytefmt::format(bytes);
    assert_eq!(&bytes_str, input);

    // Parse to specific unit
    let kb: f64 = bytefmt::parse_to(input, bytefmt::Unit::KB).unwrap();
    assert_eq!(kb, 1_230 as f64);

    // Format to specific unit
    let kb_str = bytefmt::format_to(bytes, bytefmt::Unit::KB);
    assert_eq!(&kb_str, "1230 KB");
}
Commit count: 18

cargo fmt