-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Tracking issue for slice_take
#62280
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
https://doc.rust-lang.org/nightly/std/ops/trait.OneSidedRange.html links to #69780 which is closed. Either it should be reopened (and some details filled in) or |
Can we implement Footnotes
|
Perhaps also rename |
Please, rename. Method Let me describe my actual production use case. First I read some data from file using |
FYI: #69780 is still being linked for |
I agree with @safinaskar that a different name for But changing the API to replace |
I'd love to see taking from a slice stabilized. But the introduction of
Meanwhile the The benefits of I propose the creation of a new implementation PR to remove cc @nox @cramertj @timvermeulen @ibraheemdev who worked on the previous implementation PR's. |
@safinaskar this conflict is indeed very unfortunate, however do note that there are workarounds. Notably you can:
See playground. |
@jongiddy I do find the current version with
I do not see the problem here. We have a lot of |
Perhaps Edit: Regarding the usefulness of |
I just discovered this API, after I once again reimplemented my own helper function for splitting off a prefix or suffix of a mutable slice :D Looking at the comments, my feedback:
Example:
|
|
There is precedent for |
Side note about full ranges being included in this API, but I think calling these "unbounded ranges" instead of "one-sided ranges" would make the APIs a bit clear. Even though the one-sided ranges have bounds, they still contain an unbounded side. |
I just stumbled over this feature after writing Has |
Should this also have an array version? e.g. fn take_first_chunk<'a, const N: usize>(self: &mut &'a Self) -> Option<&'a [T; N]>;
fn take_first_chunk_mut<'a, const N: usize>(self: &mut &'a mut Self) -> Option<&'a mut [T; N]>;
fn take_last_chunk<'a, const N: usize>(self: &mut &'a Self) -> Option<&'a [T; N]>;
fn take_last_chunk_mut<'a, const N: usize>(self: &mut &'a mut Self) -> Option<&'a mut [T; N]>; Would be very useful for reading and writing chunks of bytes from a slice. |
Is anything blocking these methods from being stabilized? I'd love to start using them (also, +1 on |
@JarredAllen This has been stuck on naming for years. IMO @rust-lang/libs-api should:
I don't think there are other stabilization blockers, and I don't think this benefits from a whole lot more community discussion (the original PR was sent in 2018!). @rust-lang/libs-api should make a final call on naming so that we can stabilize. |
A recent thread where these came up: https://internals.rust-lang.org/t/methods-to-pop-from-a-slice/22211?u=scottmcm |
We discussed this feature in today's standard library API team meeting. We generally liked the current design, including 6 methods ({range, first, last} × {non-mut, mut}) and OneSidedRange trait. From reviewing the discussion, our most preferred naming is |
Rename `slice::take...` methods to `split_off...` This rename was discussed and recommended in a recent t-libs meeting. cc rust-lang#62280 There's an additional commit here which modifies internals of unstable `OneSidedRange` APIs in order to implement `split_off` methods in a panic-free way (remove `unreachable!()`) as recommended in https://github.com/rust-lang/rust/pull/88502/files#r760177240. I can split this out into a separate PR if needed.
Rename `slice::take...` methods to `split_off...` This rename was discussed and recommended in a recent t-libs meeting. cc rust-lang#62280 There's an additional commit here which modifies internals of unstable `OneSidedRange` APIs in order to implement `split_off` methods in a panic-free way (remove `unreachable!()`) as recommended in https://github.com/rust-lang/rust/pull/88502/files#r760177240. I can split this out into a separate PR if needed.
Rename `slice::take...` methods to `split_off...` This rename was discussed and recommended in a recent t-libs meeting. cc rust-lang#62280 There's an additional commit here which modifies internals of unstable `OneSidedRange` APIs in order to implement `split_off` methods in a panic-free way (remove `unreachable!()`) as recommended in https://github.com/rust-lang/rust/pull/88502/files#r760177240. I can split this out into a separate PR if needed.
Rollup merge of rust-lang#136555 - cramertj:split_off, r=dtolnay Rename `slice::take...` methods to `split_off...` This rename was discussed and recommended in a recent t-libs meeting. cc rust-lang#62280 There's an additional commit here which modifies internals of unstable `OneSidedRange` APIs in order to implement `split_off` methods in a panic-free way (remove `unreachable!()`) as recommended in https://github.com/rust-lang/rust/pull/88502/files#r760177240. I can split this out into a separate PR if needed.
Should the |
@Amanieu I hadn't imagined that stabilizing this feature would stabilize |
I don't think that it should be sealed, since for example I also think that the idea of making the trait I'm less concerned about the specific name and more concerned about the exclusion of |
Any chance split_off_{first,last}_chunk{,_mut} (splitting off the first/last N elements as a reference to an array) could join in the stabilization? Those feel to me like they fit with the 6 being currently discussed for stabilization, and I'd love to have them also be available for use. |
What’s the use case for passing RangeFull to these? I saw one comment talking about using |
I agree that |
I don’t understand what you mean by that. |
Also note that the same operation can be spelled as |
Feature gate:
#![feature(slice_take)]
Public API
Steps / History
take_...
functions to slices #62282take_...
functions to slices #77065slice::take...
methods tosplit_off...
#136555Unresolved Questions
The text was updated successfully, but these errors were encountered: