credence_lib/resolve/
duration.rs

1use {
2    compris::resolve::*,
3    duration_str::*,
4    kutil_std::string::*,
5    std::{io::*, result::Result, time::*},
6};
7
8/// [Duration] that implements [Resolve].
9pub type ResolveDuration = ResolveParseStr<Duration, ParseDuration>;
10
11/// [ResolveDuration] to string.
12pub fn resolve_duration_to_string(duration: &ResolveDuration) -> Result<String, Error> {
13    Ok(duration.value.human_format())
14}
15
16//
17// ParseDuration
18//
19
20/// [ParseStr] for [Duration].
21///
22/// See [duration-str](https://docs.rs/duration-str/latest/duration_str/).
23#[derive(Clone, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
24pub struct ParseDuration {}
25
26impl ParseStr<Duration> for ParseDuration {
27    fn parse(representation: &str) -> Result<Duration, ParseError> {
28        Ok(parse(representation)?)
29    }
30}