6 releases

Uses old Rust 2015

0.1.5 Nov 9, 2018
0.1.4 Sep 21, 2018

#378 in Value formatting

Download history 6909/week @ 2024-07-29 6239/week @ 2024-08-05 7208/week @ 2024-08-12 7066/week @ 2024-08-19 6794/week @ 2024-08-26 6596/week @ 2024-09-02 5991/week @ 2024-09-09 5021/week @ 2024-09-16 6014/week @ 2024-09-23 3940/week @ 2024-09-30 7952/week @ 2024-10-07 5793/week @ 2024-10-14 6034/week @ 2024-10-21 4243/week @ 2024-10-28 5689/week @ 2024-11-04 7517/week @ 2024-11-11

23,641 downloads per month
Used in 16 crates (13 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