Expand description
Human readable data formatting.
This crate turns various data into human-readable strings.
For performance, the actual string used internally is not a String, but a CompactString so that any string 24 bytes (12 bytes on 32-bit) or less are stack allocated instead of heap allocated.
The documentation will still refer to the inner string as a String. Anything returned will also be a String.
Feature flags
| Flag | Purpose |
|---|---|
serde | Enable serde on all types |
ignore_nan_inf | Disable checking f64’s for f64::NAN, f64::INFINITY, and f64::NEG_INFINITY |
Unsigned integers:
let a = readable::Unsigned::from(1000_u16);
println!("{}", a);
// 1,000Signed integers:
let a = readable::Int::from(-1000);
println!("{}", a);
// -1,000Floats:
let a = readable::Float::from(1000.123);
let b = readable::Float::percent(1000.123);
println!("{}", a);
println!("{}", b);
// 1,000.123
// 1,000.12%Runtime:
let a = readable::Runtime::from(11111.1);
println!("{}", a);
// 3:05:11Time:
let a = std::time::Duration::from_secs(86399);
let b = readable::Time::from(a);
println!("{}", b);
// 23 hours, 59 minutes, 59 secondsComparison
All types implement Display, PartialEq, PartialEq<&str> and PartialEq for their inner number primitive.
Example 1:
let a = std::time::Duration::from_secs(86399);
let b = readable::Time::from(a);
assert!(b == "23 hours, 59 minutes, 59 seconds");This is comparing b’s inner String.
Example 2:
let a = readable::Int::from(-1000);
assert!(a == -1000);This is comparing a’s inner i64.
Example 3:
let a = readable::Unsigned::from(1000_u64);
let b = readable::Unsigned::from(1000_u64);
assert!(a == b);This compare both the u64 AND String inside a and b.
Re-exports
pub use constants::*;
Modules
Structs
- Human readable float.
- Human readable signed integer.
- Human readable “audio/video runtime” in
H:M:Sformat. - Human-readable
std::time::Duration. - Human readable unsigned integer.