6 releases

Uses old Rust 2015

0.1.5 Nov 9, 2018
0.1.4 Sep 21, 2018

#374 in Value formatting

Download history 5784/week @ 2024-10-13 6145/week @ 2024-10-20 4228/week @ 2024-10-27 5169/week @ 2024-11-03 8097/week @ 2024-11-10 9278/week @ 2024-11-17 6697/week @ 2024-11-24 9038/week @ 2024-12-01 8690/week @ 2024-12-08 5573/week @ 2024-12-15 2347/week @ 2024-12-22 2693/week @ 2024-12-29 4813/week @ 2025-01-05 5226/week @ 2025-01-12 4583/week @ 2025-01-19 4446/week @ 2025-01-26

19,088 downloads per month
Used in 15 crates (12 directly)

Custom license

47KB
1K SLoC

humanize-rs

Crates.io Docs

This lib aims at converting human-readable strings to specific types.

It's mainly used in parsing config files.

Usage

  1. Add this lib as a dependency
[dependencies]
humanize-rs = "0.1"
  1. Add the crate reference
extern crate humanize_rs;

Example

Bytes

use humanize_rs::bytes::{Bytes, Unit};

let gigabytes1 = Bytes::new(1, Unit::GiByte);
let gigabytes2 = "1 GiB".parse::<Bytes>();
assert_eq!(gigabytes1, gigabytes2);
assert_eq!(gigabytes2.unwrap().size(), 1 << 30);

Duration

use humanize_rs::duration::parse;
use std::time::Duration;

assert_eq!(parse("1h 30m 71s"), Ok(Duration::from_secs(60 * 90 + 71)));

RFC3339 Datetime

use humanize_rs::time::{Time, TimeZone};

assert_eq!(
    "2018-09-21T16:56:44.234867232+08:00".parse::<Time>(),
    Ok(Time::from_timetuple(
        2018,
        9,
        21,
        16,
        56,
        44,
        234867232,
        TimeZone::new(8).unwrap(),
    ).unwrap())
);

Contributing

Any PRs or issues are welcomed.

No runtime deps