-
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
Add [T; N]::each_ref
and [T; N]::each_mut
#75490
Add [T; N]::each_ref
and [T; N]::each_mut
#75490
Conversation
This comment has been minimized.
This comment has been minimized.
8b054a1
to
83cdd09
Compare
Oh no, not this again 😞 |
This comment has been minimized.
This comment has been minimized.
@scottmcm's arraytools calls them |
Hm I was thinking about this, and maybe it's useful to define an intermediate struct, which is like an |
This comment has been minimized.
This comment has been minimized.
I don't think a separate type is needed here. As a parallel,
I agree, and made Hopefully a future PR will allow us to consider just having that in core.
Any chance the |
Hm, if I can offer a counterpoint to |
I'd actually say that Vec totally should have map as well, because it can potentially reuse its backing memory if the target type has the same size and alignment. So map not existing (yet?) on Vec is not really an argument. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
83cdd09
to
2d244c3
Compare
[T; N]::as_ref
and [T; N]::as_mut
[T; N]::as_ref_elements
and [T; N]::as_mut_elements
I decided to only deal with the I just force pushed to name the methods |
2d244c3
to
b815ea3
Compare
/// ``` | ||
/// | ||
/// This method is particularly useful if combined with other methods, like | ||
/// [`map`](#method.map). This way, you can can avoid moving the original |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does anyone know how to use intra-doc links for this? [`map`]
and [`Self::map`]
don't work.
☔ The latest upstream changes (presumably #76265) made this pull request unmergeable. Please resolve the merge conflicts. |
2037828
to
2a1b534
Compare
I agree. |
@shepmaster Are you suggesting we should try to run crater with |
I think it's worth it. My gut says that the incidences will be much lower than |
2a1b534
to
607e322
Compare
@shepmaster I hope you are right. I don't want to be the guy that always opens the "breaks all the code" PRs 😄 I forced pushed to rename back to |
@bors try |
292ce45
to
5e90544
Compare
[T; N]::as_ref_elements
and [T; N]::as_mut_elements
[T; N]::each_ref
and [T; N]::each_mut
@dtolnay I'm not fully convinced yet, but we can still discuss the name before stabilization. I updated the PR with the names you suggested :) |
The job Click to see the possible cause of the failure (guessed by this bot)
|
These methods work very similarly to `Option`'s methods `as_ref` and `as_mut`. They are useful in several situation, particularly when calling other array methods (like `map`) on the result. Unfortunately, we can't easily call them `as_ref` and `as_mut` as that would shadow those methods on slices, thus being a breaking change (that is likely to affect a lot of code).
5e90544
to
4038042
Compare
📌 Commit 4038042 has been approved by |
Oh wow, you're fast :D I also rebased locally and was just testing. Thanks! |
⌛ Testing commit 4038042 with merge 6bb7313d5c346ae7f2397e6d61390ff288e32016... |
💥 Test timed out |
@bors retry |
☀️ Test successful - checks-actions |
This PR adds the methods
each_ref
andeach_mut
to[T; N]
. The ability to add methods to arrays was added in #75212. These two methods are particularly useful withmap
which was also added in that PR. Tracking issue: #76118