Add support for durations
ctron opened this issue · 1 comments
ctron commented
It would be great to have support for durations:
use std::time::Duration;
#[derive(Envconfig, Clone, Debug]
struct Config {
#[envconfig(from="TIMEOUT")]
pub timeout: Duration;
}
Using as:
TIMEOUT=1ms # one millisecond
TIMEOUT=1s # one second
TIMEOUT=1m # one minute
TIMEOUT=1h # one hour
# TIMEOUT=1 # fail with error: no unit
greyblake commented
@ctron The use case is valid.
However, Envconfig relies on FromStr
, which is simply not implemented for std::time::Duration
.
What I suggest to workaround this is to use humantime crate.
Please reopen the use if it does not solve your problem.