(i: &str)
| 76 | } |
| 77 | |
| 78 | fn parse_unit(i: &str) -> IResult<&str, Unit> { |
| 79 | alt(( |
| 80 | map(tag("ms"), |_| Unit::Millisecond), |
| 81 | map(tag("us"), |_| Unit::Microsecond), |
| 82 | map(tag("ns"), |_| Unit::Nanosecond), |
| 83 | map(char('h'), |_| Unit::Hour), |
| 84 | map(char('m'), |_| Unit::Minute), |
| 85 | map(char('s'), |_| Unit::Second), |
| 86 | ))(i) |
| 87 | } |
| 88 | |
| 89 | fn to_duration(num: f64, unit: Unit) -> Duration { |
| 90 | Duration::nanoseconds((num * unit.nanos() as f64).trunc() as i64) |