Add missing methods to Instant, matching Rust 1.39#17
Open
fusetim wants to merge 1 commit intotomaka:masterfrom
Open
Add missing methods to Instant, matching Rust 1.39#17fusetim wants to merge 1 commit intotomaka:masterfrom
fusetim wants to merge 1 commit intotomaka:masterfrom
Conversation
4 tasks
3aee2c2 to
39e1c28
Compare
mxinden
reviewed
Jul 14, 2021
| } | ||
|
|
||
| pub fn checked_sub(&self, duration: Duration) -> Option<Instant> { | ||
| Some(*self - duration) |
There was a problem hiding this comment.
This would allow creating a negative Instance, right?
Instant::now() - (Instant::now() + Duration::from_secs(1))
Author
There was a problem hiding this comment.
It seems, I don't know for sure if it should be avoided or not.
There was a problem hiding this comment.
I very much think this should be avoided (across the whole crate). I do think we should mimic the behavior of the standard library here.
Author
There was a problem hiding this comment.
This highly depends of the underlying implementation and could be different on an other platform. Nevertheless we could restrict the use of negative Instant.
I can't easily edit the PR for now, but I'll be back on August.
3 tasks
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.
Added some missing methods, introduced by Rust 1.39:
Instant::checked_duration_since
Instant::saturating_duration_since
Instant::checked_add
Since it is a floating number inside, this is always true.
Instant::check_sub
Since it is a floating number inside this is always true.