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"

  2. 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::(); asserteq!(gigabytes1, gigabytes2); asserteq!(gigabytes2.unwrap().size(), 1 << 30); ```

Duration

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

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

Contributing

Any PRs or issues are welcomed.