diff --git a/Cargo.toml b/Cargo.toml index 0c69d96..76dd0c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "readable" version = "0.10.0" edition = "2021" authors = ["hinto.janai "] -description = "Human readable data formatting" +description = "Human readable strings" documentation = "https://docs.rs/readable" repository = "https://github.com/hinto-janai/readable" readme = "README.md" @@ -17,8 +17,8 @@ rustc-args = ["--cfg", "docsrs"] [features] default = ["full"] byte = [] -date = [] -num = [] +date = ["once_cell", "regex"] +num = ["compact_str", "seq-macro"] run = [] str = [] time = [] @@ -31,13 +31,19 @@ full = ["serde", "bincode", "byte", "date", "num", "run", "str", "time", "toa #inline_percent = ["readable-inlined-percent"] [dependencies] -paste = "1.0.14" -seq-macro = "0.3.5" -compact_str = { version = "0.7.1", features = ["bytes", "serde"] } -regex = { version = "1.9.5" } +paste = "1.0.14" + +# (De)serialization serde = { version = "1.0.188", features = ["derive"], optional = true } bincode = { version = "2.0.0-rc.3", features = ["serde", "derive"], optional = true } -once_cell = { version = "1.18.0" } + +# Num +compact_str = { version = "0.7.1", features = ["bytes", "serde"], optional = true } +seq-macro = { version = "0.3.5", optional = true } + +# Date +regex = { version = "1.9.5", optional = true } +once_cell = { version = "1.18.0", optional = true } # Inlined crates. #readable-inlined-date = { version = "0.1.2", optional = true } diff --git a/README.md b/README.md index 56aa1e9..d604b60 100644 --- a/README.md +++ b/README.md @@ -19,45 +19,45 @@ Creation of `readable` types is relatively performant. ## Examples #### Unsigned ```rust -# use readable::*; +use readable::*; assert_eq!(Unsigned::from(1000_u64), "1,000"); ``` #### Int ```rust -# use readable::*; +use readable::*; assert_eq!(Int::from(-1000), "-1,000"); ``` #### Float ```rust -# use readable::*; +use readable::*; assert_eq!(Float::from(1000.123), "1,000.123"); ``` #### Percent ```rust -# use readable::*; +use readable::*; assert_eq!(Percent::from(1000.123), "1,000.12%"); ``` #### Runtime ```rust -# use readable::*; +use readable::*; assert_eq!(Runtime::from(311.123), "5:11"); assert_eq!(RuntimePad::from(311.123), "00:05:11"); assert_eq!(RuntimeMilli::from(311.123), "00:05:11.123"); ``` #### Time ```rust -# use readable::*; +use readable::*; assert_eq!(Time::from(86399_u32), "23h, 59m, 59s"); assert_eq!(TimeFull::from(86399_u32), "23 hours, 59 minutes, 59 seconds"); ``` #### Date ```rust -# use readable::*; +use readable::*; assert_eq!(Date::from_ymd(2014, 12, 31).unwrap(), "2014-12-31"); ``` #### Byte ```rust -# use readable::*; +use readable::*; assert_eq!(Byte::from(1234), "1.234 KB"); ``` @@ -66,20 +66,20 @@ All number types implement `PartialEq` against `str` and their internal numbers. This is comparing `b`'s inner `String`: ```rust -# use readable::*; +use readable::*; let a = std::time::Duration::from_secs(86399); let b = TimeFull::from(a); assert_eq!(b, "23 hours, 59 minutes, 59 seconds"); ``` This is comparing `a`'s inner `i64`: ```rust -# use readable::*; +use readable::*; let a = Int::from(-1000); assert_eq!(a, -1000); ``` This compares both the `u64` AND `String` inside `a` and `b`: ```rust -# use readable::*; +use readable::*; let a = Unsigned::from(1000_u64); let b = Unsigned::from(1000_u64); assert_eq!(a, b); @@ -89,34 +89,34 @@ assert_eq!(a, b); All number types implement the common arithmetic operators `+`, `-`, `/`, `*`, `%`, outputting a new `Self`. #### `+` Addition ```rust -# use readable::*; +use readable::*; let f1 = Float::from(1.0); let f2 = Float::from(2.0); assert_eq!(f1 + f2, 3.0); ``` #### `-` Subtraction ```rust -# use readable::*; +use readable::*; let p50 = Percent::from(50.0); let p25 = Percent::from(25.0); assert_eq!(p50 - p25, "25.00%"); ``` #### `/` Division ```rust -# use readable::*; +use readable::*; let u100 = Unsigned::from(100_u64); let u10 = Unsigned::from(10_u64); assert_eq!(u100 / u10, 10); ``` #### `*` Muliplication ```rust -# use readable::*; +use readable::*; let u10 = Unsigned::from(10_u64); assert_eq!(u10 * u10, Unsigned::from(100_u64)); ``` #### `%` Modulo ```rust -# use readable::*; +use readable::*; let u10 = Unsigned::from(10_u64); assert_eq!(u10 % u10, 0); ``` @@ -149,4 +149,4 @@ All major types are exported to the root, so they can be imported without specif use readable::HeadTail; // shorter, preferred. use readable::str::HeadTail; // longer -``` \ No newline at end of file +``` diff --git a/src/num/unsigned.rs b/src/num/unsigned.rs index 22450a5..c78f2ce 100644 --- a/src/num/unsigned.rs +++ b/src/num/unsigned.rs @@ -23,7 +23,7 @@ use std::num::{ /// For [`u8`], [`u16`], [`u32`], [`u64`], [`usize`] or any `NonZeroU*` variant: /// - Use [`Unsigned::from`] /// -/// Floating point and signed interger ([`f32`], [`i32`]) inputs must use [`Unsigned::try_from`] and: +/// Floating point and signed integer ([`f32`], [`i32`]) inputs must use [`Unsigned::try_from`] and: /// - (Negative) infinity floats ([`f32::INFINITY`], [`f32::NEG_INFINITY`]) /// - NaN floats ([`f32::NAN`]) /// - Signed floats (`-1.0`)