Rename checked_{sub, add}_duration to convert_{sub, add}_duration#81
Open
datdenkikniet wants to merge 3 commits into
Open
Rename checked_{sub, add}_duration to convert_{sub, add}_duration#81datdenkikniet wants to merge 3 commits into
checked_{sub, add}_duration to convert_{sub, add}_duration#81datdenkikniet wants to merge 3 commits into
Conversation
datdenkikniet
commented
May 10, 2026
|
|
||
| /// Duration between since the start of the `Instant`. This assumes an instant which | ||
| /// won't wrap within the execution of the program. | ||
| /// The duration between this instant and `Instant::from_ticks(0)`. |
Author
There was a problem hiding this comment.
It felt a bit ugly to write Instant::from_ticks(0), but we don't have an Instant::ZERO yet and "Start of the Instant" felt too ambiguous.
2509535 to
68ba800
Compare
checked_{sub, add}_duration to {sub, add}_converted_durationchecked_{sub, add}_duration to convert_{sub, add}_duration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The naming of
checked_{sub,add}_durationcan somewhat easily be interpreted as also checking the actual addition or subtraction as that is what the words imply in this order, but it is only checking the conversion. Rename them to (hopefully) reduce this ambiguity. This also aims to further improve the issues reported in #38.The old function names were also inconsistent with
std::time::Instant::checked_{add,sub}which do check for overflow during the addition or subtraction.Also add more examples to make it clear what they do.
There was also a stray
between sinceinInstant::duration_since_epochwhich I fixed.Am open to bikeshedding: other alternatives I was considering were
convert_{add,sub}_duration, andchecked_convert_{sub_add}(leaving outDurationsince there are no other addition/subtraction implementations onInstant, soDurationis implied)Alternatively, we could keep the names and just merge the updated docs with more examples.