6个版本
使用旧的Rust 2015
0.1.5 | 2018年11月9日 |
---|---|
0.1.4 | 2018年9月21日 |
#1004 在 解析器实现
每月21,250次下载
用于 15 个 包(12个直接使用)
47KB
1K SLoC
humanize-rs
这个库旨在将可读性字符串转换为特定类型。
主要用于解析配置文件。
用法
- 将此库作为依赖项添加
[dependencies]
humanize-rs = "0.1"
- 添加crate引用
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)));
RFC3339日期时间
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())
);
贡献
欢迎提交任何PR或问题。