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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
//! Human **readable** data formatting.
//!
//! This crate turns various data into human-readable strings.
//!
//! Most of the internal strings are implemented as fixed length, stack allocated arrays that are [`Copy`](https://doc.rust-lang.org/stable/std/marker/trait.Copy.html)-able.
//!
//! # Feature flags
//! | Flag | Purpose |
//! |------------------|---------|
//! | `serde` | Enables [`serde`](https://docs.rs/serde) on all types
//! | `ignore_nan_inf` | Disables checking `f64`'s for `f64::NAN`, `f64::INFINITY`, and `f64::NEG_INFINITY`
//! | `inline_date` | Inlines any `Date` that is in `YYYY-MM-HH` format and is between year `1900-2100`
//! | `inline_time` | Inlines any `Time` that is under `1 hour, 1 minute` (`0..=3660`)
//! | `inline_runtime` | Inlines ALL of `Runtime` (`0:00..99:59:59`/`0..=359999`)
//! | `inline_percent` | Inlines any `Percent` between `0.0..100.0`
//! | `full` | Enables everything above
//!
//! **Warning:** The `inline_*` features are disabled by default. While they increase speed,
//! they also _heavily_ increase build time and binary size.
//!
//! #### Unsigned integers:
//! ```
//! let a = readable::Unsigned::from(1000_u64);
//!
//! assert!(a == 1000_u64);
//! assert!(a == "1,000");
//! ```
//!
//! #### Signed integers:
//! ```
//! let a = readable::Int::from(-1000);
//!
//! assert!(a == -1000);
//! assert!(a == "-1,000");
//! ```
//!
//! #### Floats:
//! ```
//! let a = readable::Float::from(1000.123);
//!
//! assert!(a == 1000.123);
//! assert!(a == "1,000.123");
//! ```
//!
//! #### Percents:
//! ```
//! let a = readable::Percent::from(1000.123);
//!
//! assert!(a == 1000.123);
//! assert!(a == "1,000.12%");
//! ```
//!
//! #### Runtime:
//! ```
//! let a = readable::Runtime::from(11111_u16);
//!
//! assert!(a == 11111);
//! assert!(a == "3:05:11");
//! ```
//!
//! #### Time:
//! ```
//! let a = readable::Time::from(86399_u64);
//!
//! assert!(a == 86399_u64);
//! assert!(a == "23 hours, 59 minutes, 59 seconds");
//! ```
//!
//! #### Date:
//! ```rust
//! let a = readable::Date::from_str("2014-12-31").unwrap();
//!
//! assert!(a == (2014, 12, 31));
//! assert!(a == "2014-12-31");
//! ```
//!
//! # Comparison
//! All types implement `Display`, `PartialEq`, `PartialEq<&str>` and `PartialEq` for their inner number primitive.
//!
//! Example 1:
//! ```rust
//! 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:
//! ```rust
//! let a = readable::Int::from(-1000);
//!
//! assert!(a == -1000);
//! ```
//! This is comparing `a`'s inner `i64`.
//!
//! Example 3:
//! ```rust
//! let a = readable::Unsigned::from(1000_u64);
//! let b = readable::Unsigned::from(1000_u64);
//!
//! assert!(a == b);
//! ```
//! This compares both the `u64` AND `String` inside `a` and `b`.
//!
//! # Math
//! Most types implement `+, -, /, *, %`, outputting a new `Self`.
//!
//! Example - `Add +`:
//! ```rust
//! let f1 = readable::Float::from(1.0);
//! let f2 = readable::Float::from(2.0);
//! let f3 = readable::Float::from(3.0);
//!
//! assert!(f1 + f2 == f3);
//! ```
//! Example - `Sub -`:
//! ```rust
//! let p50 = readable::Percent::from(50.0);
//! let p25 = readable::Percent::from(25.0);
//!
//! assert!(p50 - p25 == "25.00%");
//! ```
//! Example - `Div /`:
//! ```rust
//! let u100 = readable::Unsigned::from(100_u64);
//! let u10 = readable::Unsigned::from(10_u64);
//!
//! assert!(u100 / u10 == 10);
//! ```
//! Example - `Mul *`:
//! ```rust
//! let u10 = readable::Unsigned::from(10_u64);
//!
//! assert!(u10 * u10 == readable::Unsigned::from(100_u64));
//! ```
//! Example - `Rem %`:
//! ```rust
//! let u10 = readable::Unsigned::from(10_u64);
//!
//! assert!(u10 % u10 == 0);
//! ```
//------ Lints
#![forbid(
future_incompatible,
let_underscore,
break_with_label_and_loop,
coherence_leak_check,
deprecated,
duplicate_macro_attributes,
exported_private_dependencies,
for_loops_over_fallibles,
large_assignments,
overlapping_range_endpoints,
private_in_public,
semicolon_in_expressions_from_macros,
redundant_semicolons,
unconditional_recursion,
unreachable_patterns,
unused_allocation,
unused_braces,
unused_comparisons,
unused_doc_comments,
unused_labels,
unused_unsafe,
while_true,
keyword_idents,
missing_docs,
non_ascii_idents,
noop_method_call,
unreachable_pub,
single_use_lifetimes,
variant_size_differences,
unused_mut,
)]
#![deny(
nonstandard_style,
)]
pub(crate) mod inner;
pub(crate) mod macros;
mod constants;
pub use constants::*;
mod date;
pub use date::*;
mod unsigned;
pub use unsigned::*;
mod int;
pub use int::*;
mod float;
pub use float::*;
mod percent;
pub use percent::*;
mod time;
pub use time::*;
mod runtime;
pub use runtime::*;