Crate lib[][src]

Expand description

This crate provides a mechanism to store numbers and display them as a multiple of the chosen power of 1000 bytes or 1024 bytes, e.g. in Megabytes or Mebibytes for human readability.

Example:

let mut bb = BytesConfig::default();
let b = bb.bytes(5247 as u16);
println!("{}", b);  //  Prints "5.25 KB"

The number is stored internally in the same type as was provided to initialize the struct: u16 in this example.

The Bytes structs are displayed using the preferences held in the BytesConfig struct that created them:

bb.set_precision(1);
println!("{}", b);  //  Prints "5.3 KB"

See example for more details.

Structs

The struct used to store the number of bytes. Trait bounds specify what traits are required from the type used to store the number of bytes. Into<u64> in particular is required as the number of bytes is temporarily converted to u64 (the only type that we are sure can store any number stored in another type without overflowing) to compare it.

This struct captures the preferences for display of bytes and creates instances of Bytes struct that contain a reference to the preferences that they must use for display. If the preferences are changed, all Bytes that the BytesConfig instanciated adopt immediately the change. Config wrapped in Mutex makes the implementation threadsafe.

Enums

Specify the possible choices for the base used for the display of bytes, i.e. Gabyte: Powers of 1000 bytes (Kilobyte, Megabyte, …) Bibyte: Powers of 1024 bytes (Kibibyte, Mebibyte, …) giving its name to the crate Ga/Bi(byte).

Constants

Array with the list of unit names to use in the power of 1024 system

Array with the list of unit names to use in the power of 1000 system

Traits

Marker trait used to indicate to the compiler what types are allowed to initialize the struct.