-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add: duration_checked_sub RFC #1640
Conversation
Signed-off-by: benaryorg <binary@benary.org>
Thanks for the RFC! This seems like a pretty reasonable addition to me -- I was actually slightly surprised it wasn't already provided. I think if we add this method, we should at least provide the other Regarding the lack of a |
cc @wycats |
Regardung the trait: I do know that, I just wanted to point out that this raises the amount of similar methods in stdlib and that others might ask why. Also, isn't it a little problematic to have those methods not umplemented as traits, as I can imagine it makes it harder for e.g. the Also when doing any maths in a generic way (outside the stdlib of course) for example to provide a complex mathematical operation in a way that it is not dependent on datatypes which might overflow it would be annoyingly hard to test for that when not having that trait at hand. Back to the scope of this RFC: You mentioned that at least all |
In my opinion the corresponding |
I'm a little concerned about the noisiness of these additions. Maybe we could have a As an aside, I think this type should return a |
I think the word you are looking for is |
What you are looking for might be the |
Well, for one primitive types are primitive and Duration primitive is not, thus comparing them is not very desirable. It seems to make sense to me for |
By "safe" you mean panicking on strange values? |
@benaryorg We haven’t anything like |
So, this |
I try not to use "safe" to mean something other than the same as the meaning of In general, I feel we would benefit from having some terminology for this, and I don't think I'm also a fan of moving these concepts in their own types, and having their failures produce |
I definitely do agree on that. Say, @wycats, what does your Implementing it for each type would have the advantage of keeping that code separated from the other Both the Please do not hesitate to correct me. |
🔔 This RFC is now entering its final comment period 🔔 The libs teams's inclination is to add this, along with other |
I'm supporting that. So, should I update the file to reflect the other methods? |
Please do! |
Signed-off-by: benaryorg <binary@benary.org>
|
||
```rust | ||
impl Duration { | ||
fn checked_sub(self, rhs: Duration) -> Duration { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the signature here should return Option<Duration>
, right?
(similarly Some(Duration)
below)
Discussed during libs triage yesterday the decision was to merge. @benaryorg could you update with the one minor nit we saw, and after that I'll merge the PR? |
Signed-off-by: benaryorg <binary@benary.org>
Okay, so, sorry for both messing up GitHub (on mobile right now, hit the close button by accident) and the original RFC, of course it should be |
Thanks @benaryorg! |
This would as described in the RFC add the method
Duration::checked_sub()
and as an unresolved question if a few other, similar methods should be added.