Crate foyer_bytesize

Source
Expand description

ByteSize is an utility that easily makes bytes size representation and helps its arithmetic operations.

§Example

use bytesize::ByteSize;

fn byte_arithmetic_operator() {
  let x = ByteSize::mb(1);
  let y = ByteSize::kb(100);

  let plus = x + y;
  print!("{} bytes", plus.as_u64());

  let minus = ByteSize::tb(100) - ByteSize::gb(4);
  print!("{} bytes", minus.as_u64());
}

It also provides its human readable string as follows:

use bytesize::ByteSize;

assert_eq!("482.4 GiB", ByteSize::gb(518).to_string_as(true));
assert_eq!("518.0 GB", ByteSize::gb(518).to_string_as(false));

Structs§

ByteSize
Byte size representation

Constants§

B
byte size for 1 byte
GB
bytes size for 1 gigabyte
GIB
bytes size for 1 gibibyte
KB
bytes size for 1 kilobyte
KIB
bytes size for 1 kibibyte
MB
bytes size for 1 megabyte
MIB
bytes size for 1 mebibyte
PB
bytes size for 1 petabyte
PIB
bytes size for 1 pebibyte
TB
bytes size for 1 terabyte
TIB
bytes size for 1 tebibyte

Functions§

gb
gib
kb
kib
mb
mib
pb
pib
tb
tib
to_string