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
- Module containing all multiples.
Structs
- The error returned when trying to create a new
SpecificSize
with an invalid value. SpecificSize
represents a size in bytes with a multiple.
Enums
- The error returned when trying to parse a
SpecificSize
, using theFromStr
trait.
Traits
- Trait to convert a
SpecificSize
to and from different multiples.
Type Definitions
- Size with a generic
Multiple
.