1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//! Human readable formatting of numbers and durations, without dependencies and without
//! allocation.
//!
//! # Numbers
//!
//! Numbers are formatted with unit prefixes, either binary (steps of 1024) or decimal (steps of
//! 1000). Byte formatting is the default, the `_no_unit` variants leave the `B` out.
//!
//! ```
//! use humanize_proper::{bin, dec, bin_no_unit, NumFmt, Prefixes};
//!
//! assert_eq!(bin(1536).to_string(), "1.5KiB");
//! assert_eq!(dec(1500).to_string(), "1.5kB");
//! assert_eq!(bin_no_unit(1536).to_string(), "1.5Ki");
//! assert_eq!(NumFmt::bin().space(true).fmt(1536).to_string(), "1.5 KiB");
//! assert_eq!(NumFmt::bin().jedec().fmt(1536).to_string(), "1.5KB");
//! ```
//!
//! Integer inputs are formatted with exact integer arithmetic, including the rollover that rounding
//! can cause:
//!
//! ```
//! # use humanize_proper::dec;
//! assert_eq!(dec(999_999u64).to_string(), "1MB");
//! ```
//!
//! # Durations
//!
//! ```
//! use humanize_proper::{dur, Dur, DurFmt, Frac, TimeUnit, Zeros};
//!
//! assert_eq!(dur(1_000_000_000u64).to_string(), "31y251d_13h21m28s");
//! assert_eq!(dur(3665u64).to_string(), "01h01m05s");
//! assert_eq!(DurFmt::new().zeros(Zeros::TrimAll).fmt(3665u64).to_string(), "1h1m5s");
//! assert_eq!(DurFmt::new().zeros(Zeros::TrimLargest).fmt(3665u64).to_string(), "1h01m05s");
//! ```
//!
//! The seconds field can carry a fraction down to attoseconds:
//!
//! ```
//! # use humanize_proper::{Dur, DurFmt, Frac};
//! let d = Dur::from_nanos(65_123_456_789);
//! assert_eq!(DurFmt::new().frac(Frac::Millis).fmt(d).to_string(), "01m05.123s");
//! assert_eq!(DurFmt::new().frac(Frac::Nanos).fmt(d).to_string(), "01m05.123456789s");
//! ```
//!
//! # Display behavior
//!
//! Both formatters return values implementing [`core::fmt::Display`] and render through
//! [`core::fmt::Formatter::pad`], so width, alignment and fill work as usual:
//!
//! ```
//! # use humanize_proper::bin;
//! assert_eq!(format!("{:>10}", bin(1536)), " 1.5KiB");
//! ```
pub use ;
pub use ;
pub use ;
/// Formats a byte count with binary prefixes, e.g. `1.5KiB`.
///
/// ```
/// # use humanize_proper::bin;
/// assert_eq!(bin(1_048_576).to_string(), "1MiB");
/// ```
/// Formats a byte count with SI prefixes, e.g. `1.5kB`.
///
/// ```
/// # use humanize_proper::dec;
/// assert_eq!(dec(1_000_000).to_string(), "1MB");
/// ```
/// Formats a number with binary prefixes and no unit, e.g. `1.5Ki`.
///
/// ```
/// # use humanize_proper::bin_no_unit;
/// assert_eq!(bin_no_unit(1_048_576).to_string(), "1Mi");
/// ```
/// Formats a number with SI prefixes and no unit, e.g. `1.5k`.
///
/// ```
/// # use humanize_proper::dec_no_unit;
/// assert_eq!(dec_no_unit(1_000_000).to_string(), "1M");
/// ```
/// Formats a duration in the default style, e.g. `32y007d_05h01m05s`.
///
/// ```
/// # use humanize_proper::dur;
/// assert_eq!(dur(90).to_string(), "01m30s");
/// ```