Open sbromling opened 2 years ago
Another option is to just move the <Duration as From<StdDuration>>::from
method into an inherent impl instead (and then have the trait just call the inherent method), which would have the effect of making a call to Duration::from()
become constant.
Personally I like the idea of making the inner field public, because it feels simpler to say Duration(StdDuration::from_secs(2))
instead of Duration::from(StdDuration::from_secs(2))
and there doesn't seem to be any obvious reason why it would ever need a new field, it's just a newtype wrapper and does not impose any constraints on its wrapped value.
Since
Duration
s can be created withconst fn
s, it would be nice ifhumantime::Duration
could also.It would be ideal if
From
andInto
could be const. Since I don't believe that's possible, perhaps the following added tohumantime::Duration
:Alternatively, would it be feasible to make the inner
StdDuration
public (i.e.pub struct Duration(pub StdDuration)
)? Then the const initializer wouldn't be strictly necessary, and it would give other convenient ways to access the inner duration (i.e. without using theInto
orDeref
+Copy
impls).I was excited to discover this crate today, because it is a pretty good fit for
clap
derive-style argument parsing, thanks to the addition ofFromStr
andDisplay
, plus making the command line fields "unit-less" and less error-prone.