6 releases

Uses old Rust 2015

0.1.5 Nov 9, 2018
0.1.4 Sep 21, 2018

#330 in Value formatting

Download history 6308/week @ 2023-11-20 6004/week @ 2023-11-27 4490/week @ 2023-12-04 3406/week @ 2023-12-11 6211/week @ 2023-12-18 2832/week @ 2023-12-25 4390/week @ 2024-01-01 4010/week @ 2024-01-08 5848/week @ 2024-01-15 5692/week @ 2024-01-22 5517/week @ 2024-01-29 4213/week @ 2024-02-05 5473/week @ 2024-02-12 5259/week @ 2024-02-19 6650/week @ 2024-02-26 6097/week @ 2024-03-04

23,581 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