Crate human_size

source ·
Expand description

The human_size crate represents sizes for humans.

The main type is SpecificSize, which (as the name might suggests) represents a size in specific multiple. Alternatively Size can be used to represent a size with a generic multiple (not defined at compile type).

Example

Below is small example that parses a size from a string and prints it.

use human_size::{Size, SpecificSize, Kilobyte};

let size1: Size = "10000 B".parse().unwrap();
assert_eq!(size1.to_string(), "10000 B");

// Or using a specific multiple.
let size2: SpecificSize<Kilobyte> = "10000 B".parse().unwrap();
assert_eq!(size2.to_string(), "10 kB");

// Generic and specific sizes can be compared.
assert_eq!(size1, size2);

Notes

Internally f64 is used to represent the size, so when comparing sizes with different multiples be wary of rounding errors related to usage of floating point numbers.

Re-exports

Modules

Structs

Enums

Traits

Type Definitions