7 releases

Uses old Rust 2015

0.1.7 Nov 8, 2018
0.1.6 Nov 8, 2018

#2730 in Parser implementations

Download history 2395/week @ 2024-07-26 2933/week @ 2024-08-02 2898/week @ 2024-08-09 2511/week @ 2024-08-16 2420/week @ 2024-08-23 2493/week @ 2024-08-30 2212/week @ 2024-09-06 2647/week @ 2024-09-13 2016/week @ 2024-09-20 2362/week @ 2024-09-27 2562/week @ 2024-10-04 2541/week @ 2024-10-11 2470/week @ 2024-10-18 2541/week @ 2024-10-25 2484/week @ 2024-11-01 2155/week @ 2024-11-08

10,090 downloads per month
Used in 17 crates (13 directly)

MIT/Apache

19KB
277 lines

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");
}

Dependencies

~2–3MB
~54K SLoC