-
Notifications
You must be signed in to change notification settings - Fork 19
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
ACP: Duration::abs_diff
#291
Labels
ACP-accepted
API Change Proposal is accepted (seconded with no objections)
api-change-proposal
A proposal to add or alter unstable APIs in the standard libraries
T-libs-api
Comments
elomatreb
added
api-change-proposal
A proposal to add or alter unstable APIs in the standard libraries
T-libs-api
labels
Nov 5, 2023
Seconded; please send a standard library PR! Thanks. |
dtolnay
added
the
ACP-accepted
API Change Proposal is accepted (seconded with no objections)
label
Nov 5, 2023
This was referenced Nov 5, 2023
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Nov 21, 2023
…homcc Add `Duration::abs_diff` This adds a `Duration::abs_diff` method analogous to the existing one on the primitive integers. ACP: rust-lang/libs-team#291 Tracking Issue: rust-lang#117618
bors
added a commit
to rust-lang/miri
that referenced
this issue
Nov 21, 2023
Add `Duration::abs_diff` This adds a `Duration::abs_diff` method analogous to the existing one on the primitive integers. ACP: rust-lang/libs-team#291 Tracking Issue: rust-lang/rust#117618
lnicola
pushed a commit
to lnicola/rust-analyzer
that referenced
this issue
Apr 7, 2024
Add `Duration::abs_diff` This adds a `Duration::abs_diff` method analogous to the existing one on the primitive integers. ACP: rust-lang/libs-team#291 Tracking Issue: rust-lang/rust#117618
RalfJung
pushed a commit
to RalfJung/rust-analyzer
that referenced
this issue
Apr 27, 2024
Add `Duration::abs_diff` This adds a `Duration::abs_diff` method analogous to the existing one on the primitive integers. ACP: rust-lang/libs-team#291 Tracking Issue: rust-lang/rust#117618
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
ACP-accepted
API Change Proposal is accepted (seconded with no objections)
api-change-proposal
A proposal to add or alter unstable APIs in the standard libraries
T-libs-api
Proposal
Problem statement
I would like to be able to get the absolute difference between two
std::time::Duration
values, without going through a manual "compare and subtract" dance.Motivating examples or use cases
In a personal project I have some code that compares durations of music albums, and considers them close enough if they are within a certain threshold (because of sub-second rounding differences).
Solution sketch
I would like to propose adding a
Duration::abs_diff
method mirroring the existingabs_diff
methods on primitive integers.Alternatives
It's perfectly possible to do this sort of thing using existing APIs, but it's verbose and potentially error-prone (e.g. the order of operations might be the wrong way around leading to a potential runtime panic). The manual implementation would be the following:
Links and related work
n/a
What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution:
The text was updated successfully, but these errors were encountered: