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§

pub use multiples::*;

Modules§

multiples
Module containing all multiples.

Structs§

InvalidValueError
The error returned when trying to create a new SpecificSize with an invalid value.
SpecificSize
SpecificSize represents a size in bytes with a multiple.

Enums§

ParsingError
The error returned when trying to parse a SpecificSize, using the FromStr trait.

Traits§

Multiple
Trait to convert a SpecificSize to and from different multiples.

Type Aliases§

Size
Size with a generic Multiple.