Skip to content

Commit

Permalink
0.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hinto-janai committed Oct 4, 2023
1 parent 80af335 commit f590c56
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
22 changes: 14 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "readable"
version = "0.10.0"
edition = "2021"
authors = ["hinto.janai <[email protected]>"]
description = "Human readable data formatting"
description = "Human readable strings"
documentation = "https://docs.rs/readable"
repository = "https://github.com/hinto-janai/readable"
readme = "README.md"
Expand All @@ -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 = []
Expand All @@ -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 }
Expand Down
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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");
```

Expand All @@ -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);
Expand All @@ -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);
```
Expand Down Expand Up @@ -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
```
```
2 changes: 1 addition & 1 deletion src/num/unsigned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down

0 comments on commit f590c56

Please sign in to comment.