Crate bytefmt

Source
Expand description

§bytefmt

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

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

Enums§

Unit

Constants§

B
GB
GIB
KB
KIB
MB
MIB
PB
PIB
TB
TIB

Functions§

format
Format bytes to byte string
format_to
Format bytes to specific unit byte string
parse
Parse given string to bytes count
parse_to
Parse given string to specific byte unit