-
Notifications
You must be signed in to change notification settings - Fork 13k
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 get_pin_ref and get_pin_mut methods to slice #78370
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
66ff7e9
to
e694a19
Compare
This comment has been minimized.
This comment has been minimized.
/// ``` | ||
#[unstable(feature = "slice_get_pin", issue = "none")] | ||
#[inline] | ||
pub fn get_pin_mut<I>(self: Pin<&mut Self>, index: I) -> Option<Pin<&mut I::Output>> |
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.
The existence of this method means that unsafe code needs to be careful when projecting from a Pin<&mut [T]>
to a &mut T
(a mutable reference to one of the slice elements). It can still be done soundly, but the &mut T
cannot be moved out of if the Pin<&mut [T]>
is ever exposed to safe code (which could call get_pin_mut
).
I think it would be good to mention this in the docs.
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.
That is correct. Option::as_pin_mut
also has the same issue. We need to add docs to both.
assigning back to author - not sure if this is done |
@taiki-e Ping from triage. It seems the next step for this PR would be update the docs and switching this PR to S-waiting-on-review? |
Closing this due to inactivity. |
This adds methods to return a pinned reference to an element or subslice from a pinned slice.
Motivation: https://users.rust-lang.org/t/working-with-pinned-slices-are-there-any-structurally-pinning-vec-like-collection-types/50634
Suffix (
*_pin_{ref, mut}
) is based on Option'sas_pin_{ref, mut}
methods.