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

Rename ManuallyDrop::take to read #62198

Closed
wants to merge 2 commits into from
Closed
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
19 changes: 11 additions & 8 deletions src/libcore/mem/manually_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,30 @@ impl<T> ManuallyDrop<T> {
slot.value
}

/// Takes the contained value out.
/// Reads the value from the `ManuallyDrop<T>` container. The resulting `T` is subject
/// to the usual drop handling.
///
/// This method is primarily intended for moving out values in drop.
/// Instead of using [`ManuallyDrop::drop`] to manually drop the value,
/// you can use this method to take the value and use it however desired.
/// `Drop` will be invoked on the returned value following normal end-of-scope rules.
/// you can use this method to read the value and use it however desired.
///
/// If you have ownership of the container, you can use [`ManuallyDrop::into_inner`] instead.
/// Whenever possible, it is preferable to use [`into_inner`][`ManuallyDrop::into_inner`]
/// instead, which prevents duplicating the content of the `ManuallyDrop<T>`.
///
/// # Safety
///
/// This function semantically moves out the contained value without preventing further usage.
/// It is up to the user of this method to ensure that this container is not used again.
/// Like [`std::ptr::read`], this function semantically moves out the contained value
/// without preventing further usage, leaving the state of the container unchanged.
/// It is your responsibility to ensure that this `ManuallyDrop` is not reused after `read`.
///
/// [`ManuallyDrop::drop`]: #method.drop
/// [`ManuallyDrop::into_inner`]: #method.into_inner
/// [`std::ptr::read`]: ../ptr/fn.read.html
#[must_use = "if you don't need the value, you can use `ManuallyDrop::drop` instead"]
#[unstable(feature = "manually_drop_take", issue = "55422")]
#[inline]
pub unsafe fn take(slot: &mut ManuallyDrop<T>) -> T {
ManuallyDrop::into_inner(ptr::read(slot))
pub unsafe fn read(slot: &mut ManuallyDrop<T>) -> T {
ptr::read(&slot.value)
}
}

Expand Down