Hello. I have read conversation about duration at Duration::zero() -> Duration::ZERO by workingjubilee · Pull Request #78216 · rust-lang/rust · GitHub and I would like to share some ideas how to improve it.
I see two usecases for Duration
I need some value for thread::sleep and similar methods - clearly negative duration makes no sense there and should
- be impossible
- cause panic
- behave as zero duration (e.g. this actually happen in golang)
And there is another kind of duration, when I want calculate difference between two timestamps surely here I need negative durations. The problem of MIN duration can be solved the same way as for real numbers. There is smallest positive non zero value, which could be applied to duration too if needed, and similar value exists for negative real number - so could be also for duration - but for "smallest negative" duration (negative and closest to zero) I see no usecase.
These two usecases can be covered by single type in case of 1.1. or 1.3. (preferably 1.3.) or by two types, in case of 1.1.
To prevent BC break, another type should be introduced, e.g. TimeDifference with some nice conversion to Duration and back.