-
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
RFC: .drain(range)
and .drain()
#1257
Conversation
Previous Vec::drain RFC: /pull/574 |
@bluss Sorry for the lack of commentary! I was wondering if you can elaborate on the motivation for
but it's not entirely clear to me what you mean. Compared to the OTOH, |
It doesn't have to be a trait, it could be a function (parameterized over a different trait), to implement the same kind of bounds checking. That's mostly just to not have to repeat it in Vec::drain, String::drain, VecDeque::drain etc.
This refers mostly to other trait ideas that would convert all ranges to either a half open or closed range. These fail on tricky extreme values, since the maximum inclusive range does not fit inside an half open range without overflow, and So yes, I think an accessor for
|
I disagree with that: I'm concerned mostly about the public-facing API here. I'd much rather stabilize a general-purpose trait like |
Do you mean you disagree with replacing it? You can't disagree that it was added to support .drain(). That's how it was added. That's ok, I didn't really consider writing the general purpose range trait for this RFC, inclusive ranges were not even ready. Should it be part of this RFC? |
I disagree that its design is specific to drain. It doesn't really matter if drain happens to be the first API that wanted it :) |
I propose the range trait gets its own RFC and is removed from this one. |
cc @Stebalien We're writing a general range trait |
I agree with @aturon that it'd be nice to have the trait here be a more general than just for these collections its targeting. Avoiding I'd also personally prefer the trait to be considered as part of this RFC as it's difficult to stabilize the methods on collections without stabilizing the traits that they're parameterizing over. It's not unheard of, but it'd make me more comfortable to stabilize everything at once. |
@alexcrichton BTreeMap goes its own road (see the BTreeMap range RFC), and as noted here in this RFC, its drain should foremost be part of or consistent with its range iterator API. It doesn't look like they will use something similar to the index ranges that Vec::drain uses. |
BTreeMap's own road for drain is over at /pull/1254 |
I think we are getting derailed.
My aim here is to get put down on paper a mandate to implement My main questions that we need to get out of the way:
In my opinion, these are the questions that are blocking stabilization of any of the The range trait questions can be settled later. |
🔔 This RFC is now entering its week-long final comment period 🔔 |
I'm personally OK with all stabilization and such here given that the trait to accept multiple ranges remains unstable (which I believe this is suggesting) |
Inherent methods are fine -- this isn't the time to add collection traits (still want HKT for that) and I don't think we want something one-off here. A trait can always be added later if the abstraction is called for.
Yes, I think it's OK. |
Thanks again for the RFC @bluss! The libs team discussed this RFC today and the decision was to merge, so I will do so. I'll also be reusing the stabilization issue as a tracking issue: rust-lang/rust#27711 |
Great. Thanks everyone for the input. |
RFC:
.drain(range)
and.drain()
Implement
.drain(range)
and.drain()
respectively as appropriate on collections.Rendered