2 releases

0.1.1 Nov 15, 2015
0.1.0 Jul 13, 2015

#76 in Value formatting

MIT license

7KB
193 lines

capsize

Build Status

Conversions between units of capacity

docs

Find them here

install

Add the following to your Cargo.toml

[dependencies]
capsize = "0.1.0"

usage

extern crate capsize;

use capize::Capacity;

pub fn main() {
  // get the equivilent number of bytes in 4 megabytes
  let bytes = 4.megabytes();
  println!("4 megabytes is {} bytes", bytes);
  // resolve byte size to the closest human form
  println!(bytes.capacity()); // 4.0K
}

Doug Tangren (softprops) 2015


lib.rs:

Capsize

Capsize provides conversions between units of capacity, similar in nature to Duration, which provides conversions between units of time.

All conversions are represented as an i64 by default.

This crate also provides FromStr implementations that parse values "1k" into their corresponding capacity in i64 format in bytes.

Examples

use capsize::Capacity;

// convert to kilobytes to bytes
let bytes = 4.kilobytes();
assert_eq!(bytes, 4096);

// resolve 4096 to the closest human readable form
assert_eq!(bytes.capacity(), "4.0K");

No runtime deps