Crates.io | humanize-rs |
lib.rs | humanize-rs |
version | 0.1.5 |
source | src |
created_at | 2018-09-18 15:01:14.089296 |
updated_at | 2018-11-09 03:21:36.131383 |
description | For parsing human-readable strings to some types. |
homepage | https://github.com/dtynn/humanize-rs |
repository | https://github.com/dtynn/humanize-rs |
max_upload_size | |
id | 85368 |
size | 47,388 |
This lib aims at converting human-readable strings to specific types.
It's mainly used in parsing config files.
[dependencies]
humanize-rs = "0.1"
extern crate humanize_rs;
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);
use humanize_rs::duration::parse;
use std::time::Duration;
assert_eq!(parse("1h 30m 71s"), Ok(Duration::from_secs(60 * 90 + 71)));
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())
);
Any PRs or issues are welcomed.