1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use std::str::FromStr;
use std::ops::Deref;
use std::time::Duration as StdDuration;
use duration::{parse_duration, Error};
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub struct Duration(StdDuration);
impl AsRef<StdDuration> for Duration {
fn as_ref(&self) -> &StdDuration { &self.0 }
}
impl Deref for Duration {
type Target = StdDuration;
fn deref(&self) -> &StdDuration { &self.0 }
}
impl Into<StdDuration> for Duration {
fn into(self) -> StdDuration { self.0 }
}
impl From<StdDuration> for Duration {
fn from(dur: StdDuration) -> Duration { Duration(dur) }
}
impl FromStr for Duration {
type Err = Error;
fn from_str(s: &str) -> Result<Duration, Error> {
parse_duration(s).map(Duration)
}
}