Summary
This RFC adds the checked_* methods already known from primitives like
usize to Duration.
Motivation
Generally this helps when subtracting Durations which can be the case quite
often.
One abstract example would be executing a specific piece of code repeatedly after a constant amount of time.
Specific examples would be a network service or a rendering process emitting a constant amount of frames per second.
Example code would be as follows:
// This function is called repeatedly
Of course it is also suitable to not introduce panic!()s when adding
Durations.
Detailed design
The detailed design would be exactly as the current sub() method, just
returning an Option<Duration> and passing possible None values from the
underlying primitive types:
The same accounts for all other added methods, namely:
checked_add()checked_sub()checked_mul()checked_div()
Drawbacks
None.
Alternatives
The alternatives are simply not doing this and forcing the programmer to code the check on their behalf. This is not what you want.
Unresolved questions
None.