-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 saturating methods for Duration
#76114
Conversation
r? @shepmaster (rust_highfive has picked a reviewer for you, use r? to override) |
044ca51
to
904ec9f
Compare
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.
Minor nits.
Why the PR close? |
@shepmaster I really don't know what happened. I never meant to close this! |
904ec9f
to
30aa7dd
Compare
@shepmaster @pickfire I think i've addressed all the comments 👍 |
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.
Looks good to me except the mentioned doc changes.
30aa7dd
to
b869aa5
Compare
@pickfire I've fixed the docs according to your comments 👍 |
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.
Looks good to me.
@bors r+ rollup |
📌 Commit b869aa5 has been approved by |
…, r=shepmaster Add saturating methods for `Duration` In some project, I needed a `saturating_add` method for `Duration`. I implemented it myself but i thought it would be a nice addition to the standard library as it matches closely with the integers types. 3 new methods have been introduced and are gated by the new `duration_saturating_ops` unstable feature: * `Duration::saturating_add` * `Duration::saturating_sub` * `Duration::saturating_mul` If have left the tracking issue to `none` for now as I want first to understand if those methods would be acceptable at all. If agreed, I'll update the PR with the tracking issue. Further more, to match the behavior of integers types, I introduced 2 associated constants: * `Duration::MIN`: this one is somehow a duplicate from `Duration::zero()` method, but at the time this method was added, `MIN` was rejected as it was considered a different semantic (see rust-lang#72790 (comment)). * `Duration::MAX` Both have been gated by the already existing unstable feature `duration_constants`, I can introduce a new unstable feature if needed or just re-use the `duration_saturating_ops`. We might have to decide whether: * `MIN` should be replaced by `ZERO`? * associated constants over methods?
Rollup of 7 pull requests Successful merges: - rust-lang#76114 (Add saturating methods for `Duration`) - rust-lang#76297 (rustdoc: fix min_const_generics with ty::Param) - rust-lang#76484 (Add MaybeUninit::assume_init_drop.) - rust-lang#76530 (Eliminate mut reference UB in Drop impl for Rc<T>) - rust-lang#76583 (Update `std::os` module documentation.) - rust-lang#76599 (Finish off revisions for const generics UI tests.) - rust-lang#76615 (Add missing examples on binary core traits) Failed merges: r? `@ghost`
…ax, r=m-ou-se Stabilize Duration::MAX Following the suggested direction from rust-lang#76416 (comment), this PR proposes that `Duration::MAX` should have been part of the `duration_saturating_ops` feature flag all along, having been 0. heavily referenced by that feature flag 1. an odd duck next to most of `duration_constants`, as I expressed in rust-lang#57391 (comment) 2. introduced in rust-lang#76114 which added `duration_saturating_ops` and accordingly should be folded into `duration_saturating_ops` and therefore stabilized. r? `@m-ou-se`
In some project, I needed a
saturating_add
method forDuration
. I implemented it myself but i thought it would be a nice addition to the standard library as it matches closely with the integers types.3 new methods have been introduced and are gated by the new
duration_saturating_ops
unstable feature:Duration::saturating_add
Duration::saturating_sub
Duration::saturating_mul
If have left the tracking issue to
none
for now as I want first to understand if those methods would be acceptable at all. If agreed, I'll update the PR with the tracking issue.Further more, to match the behavior of integers types, I introduced 2 associated constants:
Duration::MIN
: this one is somehow a duplicate fromDuration::zero()
method, but at the time this method was added,MIN
was rejected as it was considered a different semantic (see core/time: Add Duration methods for zero #72790 (comment)).Duration::MAX
Both have been gated by the already existing unstable feature
duration_constants
, I can introduce a new unstable feature if needed or just re-use theduration_saturating_ops
.We might have to decide whether:
MIN
should be replaced byZERO
?