-
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
Tracking issue for slice::IterMut::as_slice and vec::Drain::as_slice #58957
Comments
If this feature is accepted, they should implement |
Good point, I didn't notice that |
I actually didn't notice either until I went digging in for a totally separate issue. Will have a PR for that separately, although I won't include |
Is there a reason to not add as_slice_mut for these? Particularly IterMut, where it makes the iteration over mutable pairs nicer. |
@talchas Only |
|
Yes, as long as it borrows from the let mut iter = slice.iter_mut();
while let Some(x) = iter.next() {
for y in iter.as_slice_mut() {
// x and y are distinct `&mut T`
}
} |
Yeah, exactly that. |
What is the status of this? Is anything required for stabilization other than someone to propose stabilization, make a stabilization PR, and FCP? In rowan, rust-analyzer's syntax tree backend, we're currently trying to remove unneeded allocations from syntax node cache hits. A simple patch that just does so via an arrayvec already sees a 5% improvement on rust-analyzer's main integration benchmark (not rowan's, and not purely parsing!), but being able to use the fact that |
impl AsRef<[T]> for vec::IntoIter<T> Adds `impl<T> AsRef<[T]> for vec::IntoIter<T>`. This mirrors the same trait impl for [`slice::Iter`](https://doc.rust-lang.org/nightly/std/slice/struct.Iter.html). Both types already offer `fn as_slice(&self) -> &[T]`, this just adds the trait impl for `vec::IntoIter`. If/when `fn as_slice(&self) -> &[T]` stabilizes for `vec::Drain` and `slice::IterMut`, they should get `AsRef<[T]>` impls as well. As thus, tangentially related to rust-lang#58957. My ultimate goal here: being able to use `for<T, I: Iterator<Item=T> + AsRef<[T]>> I` to refer to `vec::IntoIter`, `vec::Drain`, and eventually `array::IntoIter`, as an approximation of the set of by-value iterators that can be "previewed" as by-ref iterators. (Actually expressing that as a trait requires GAT.)
Stabilize vec::Drain::as_slice and add `AsRef<[T]> for Drain<'_, T>`. Tracking issue: rust-lang#58957. Does not stabilize `slice::IterMut::as_slice` yet. cc @cuviper This PR proposes stabilizing just the `vec::Drain::as_slice` part of that tracking issue. My ultimate goal here: being able to use `for<T, I: Iterator<Item=T> + AsRef<[T]>> I` to refer to `vec::IntoIter`, `vec::Drain`, and eventually `array::IntoIter`, as an approximation of the set of by-value iterators that can be "previewed" as by-ref iterators. (Actually expressing that as a trait requires GAT.)
Stabilize vec::Drain::as_slice and add `AsRef<[T]> for Drain<'_, T>`. Tracking issue: rust-lang#58957. Does not stabilize `slice::IterMut::as_slice` yet. cc @cuviper This PR proposes stabilizing just the `vec::Drain::as_slice` part of that tracking issue. My ultimate goal here: being able to use `for<T, I: Iterator<Item=T> + AsRef<[T]>> I` to refer to `vec::IntoIter`, `vec::Drain`, and eventually `array::IntoIter`, as an approximation of the set of by-value iterators that can be "previewed" as by-ref iterators. (Actually expressing that as a trait requires GAT.)
One of thse (vec::Drain::as_slice) is already stabilized. As for the other one: we discussed this tracking issue in the libs meeting, and would be happy to see a stabilization PR. |
Much like rust-lang#72584. As per rust-lang#58957 there's no blocker for this, and I wanted to use this today :-)
slice: Stabilize IterMut::as_slice. Much like rust-lang#72584. As per rust-lang#58957 there's no blocker for this, and I wanted to use this today :-) Closes rust-lang#58957
This issue tracks stabilization for 2 methods added in #58924:
core::slice::IterMut::as_slice
alloc::vec::Drain::as_slice
The text was updated successfully, but these errors were encountered: