Skip to content
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 Pin::{into_inner,into_inner_unchecked} #60165

Merged
merged 1 commit into from
Apr 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/libcore/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,18 @@ where
// around pinning.
unsafe { Pin::new_unchecked(pointer) }
}

/// Unwraps this `Pin<P>` returning the underlying pointer.
///
/// This requires that the data inside this `Pin` is [`Unpin`] so that we
/// can ignore the pinning invariants when unwrapping it.
///
/// [`Unpin`]: ../../std/marker/trait.Unpin.html
#[unstable(feature = "pin_into_inner", issue = "60245")]
#[inline(always)]
pub fn into_inner(pin: Pin<P>) -> P {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expected we'd call this method unpin, though maybe that's too clever.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either seems fine to me, let me know if I should change it.

pin.pointer
}
}

impl<P: Deref> Pin<P> {
Expand Down Expand Up @@ -434,6 +446,28 @@ impl<P: Deref> Pin<P> {
pub fn as_ref(self: &Pin<P>) -> Pin<&P::Target> {
unsafe { Pin::new_unchecked(&*self.pointer) }
}

/// Unwraps this `Pin<P>` returning the underlying pointer.
///
/// # Safety
///
/// This function is unsafe. You must guarantee that you will continue to
/// treat the pointer `P` as pinned after you call this function, so that
/// the invariants on the `Pin` type can be upheld. If the code using the
/// resulting `P` does not continue to maintain the pinning invariants that
/// is a violation of the API contract and may lead to undefined behavior in
/// later (safe) operations.
///
/// If the underlying data is [`Unpin`], [`Pin::into_inner`] should be used
/// instead.
///
/// [`Unpin`]: ../../std/marker/trait.Unpin.html
/// [`Pin::into_inner`]: #method.into_inner
#[unstable(feature = "pin_into_inner", issue = "60245")]
#[inline(always)]
pub unsafe fn into_inner_unchecked(pin: Pin<P>) -> P {
pin.pointer
}
}

impl<P: DerefMut> Pin<P> {
Expand Down