-
Notifications
You must be signed in to change notification settings - Fork 20
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
RangeBound::into_bounds
#538
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
We talked about this in today's @rust-lang/libs-api meeting. We were generally in favor of alternative 1, adding Also, |
This was referenced Feb 12, 2025
workingjubilee
added a commit
to workingjubilee/rustc
that referenced
this issue
Feb 14, 2025
add `IntoBounds` trait for `range_into_bounds` feature Tracking issue: rust-lang#136903 ACP: rust-lang/libs-team#538
workingjubilee
added a commit
to workingjubilee/rustc
that referenced
this issue
Feb 14, 2025
add `IntoBounds` trait for `range_into_bounds` feature Tracking issue: rust-lang#136903 ACP: rust-lang/libs-team#538
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this issue
Feb 14, 2025
Rollup merge of rust-lang#136904 - pitaj:range-into_bounds, r=tgross35 add `IntoBounds` trait for `range_into_bounds` feature Tracking issue: rust-lang#136903 ACP: rust-lang/libs-team#538
github-actions bot
pushed a commit
to rust-lang/rustc-dev-guide
that referenced
this issue
Feb 17, 2025
add `IntoBounds` trait for `range_into_bounds` feature Tracking issue: #136903 ACP: rust-lang/libs-team#538
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
The
RangeBounds
trait is typically used to make APIs generic over the variousRange
types. However,RangeBounds
only allows the user to access the bounds by reference, not by value. This means that getting an owned value requires cloning, which can be expensive (BigInt
for example), if it's even possible.It is also not very ergonomic to get each bound separately and then clone it, which commonly results in the following verbose pattern:
Motivating examples or use cases
oxc
gstreamer-rs
readyset
artichoke
nakamoto
fontations
Endless more in this Github code search
Solution sketch
RangeBounds
is an unsealed trait, so this must be added as a provided method. The only way to add the provided method withoutT: Clone
is for it to have a limiting bound.Alternatives
RangeBounds
at all?RangeBounds
is already commonly imported for these purposes, so is significantly more discoverable. People expect something like this to be onRangeBounds
.Into
instead of a new traitThis would work. But adding conversion impls like this could conflict with the new range type initiative, since currently
.into()
can only ever convert between new and old range types.Links and related work
TwoSidedRange
ACP commentsWhat 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: