Skip to content

aprimadi/parse-duration-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

parse-duration-rs

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"

Example

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))
}

Author

Armin Primadi https://github.com/aprimadi (@ Sahamee)

About

Rust library to parse Golang-style duration string

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages