Skip to content

Rename checked_{sub, add}_duration to convert_{sub, add}_duration#81

Open
datdenkikniet wants to merge 3 commits into
korken89:masterfrom
datdenkikniet:epoch_doc
Open

Rename checked_{sub, add}_duration to convert_{sub, add}_duration#81
datdenkikniet wants to merge 3 commits into
korken89:masterfrom
datdenkikniet:epoch_doc

Conversation

@datdenkikniet

@datdenkikniet datdenkikniet commented May 10, 2026

Copy link
Copy Markdown

The naming of checked_{sub,add}_duration can 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 since in Instant::duration_since_epoch which I fixed.

Am open to bikeshedding: other alternatives I was considering were convert_{add,sub}_duration, and checked_convert_{sub_add} (leaving out Duration since there are no other addition/subtraction implementations on Instant, so Duration is implied)

Alternatively, we could keep the names and just merge the updated docs with more examples.

Comment thread src/instant.rs

/// 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)`.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@datdenkikniet datdenkikniet force-pushed the epoch_doc branch 2 times, most recently from 2509535 to 68ba800 Compare May 10, 2026 11:26
@datdenkikniet datdenkikniet changed the title Rename checked_{sub, add}_duration to {sub, add}_converted_duration Rename checked_{sub, add}_duration to convert_{sub, add}_duration May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant