Crates.io | go-parse-duration |
lib.rs | go-parse-duration |
version | 0.1.1 |
source | src |
created_at | 2021-07-17 16:52:37.768603 |
updated_at | 2021-07-17 16:59:25.917332 |
description | Rust port to Golang parse duration. |
homepage | https://github.com/aprimadi/parse-duration-rs |
repository | https://github.com/aprimadi/parse-duration-rs |
max_upload_size | |
id | 424090 |
size | 10,578 |
parse-duration-rs is a Rust port of Golang parse duration time.ParseDuration
.
It parses a duration string in a short form such as 100ms
, 1h45m
, and 3ns
and return duration in nanoseconds.
The crate is called go-parse-duration
and you can depend on it via cargo:
[dependencies]
go-parse-duration = "0.1"
use go_parse_duration::{parse_duration, Error};
fn parse() -> Result<i64, Error> {
let d = parse_duration("300us")?;
Ok(d)
}
Usage with Chrono
Converting to Chrono duration can be done easily:
use chrono::Duration;
use go_parse_duration::{parse_duration, Error};
fn parse() -> Result<Duration, Error> {
let d = parse_duration("1m")?;
Ok(Duration::nanoseconds(d))
}
Armin Primadi https://github.com/aprimadi (@ Sahamee)