Skip to content

Commit 0757c0f

Browse files
committedOct 28, 2018
1 parent f32f111 commit 0757c0f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
 

‎src/libcore/mem.rs

+20
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,26 @@ impl<T> ManuallyDrop<T> {
973973
pub fn into_inner(slot: ManuallyDrop<T>) -> T {
974974
slot.value
975975
}
976+
977+
/// Takes the contained value out.
978+
///
979+
/// This method is primarily intended for moving out values in drop.
980+
/// Instead of using [`ManuallyDrop::drop`] to manually drop the value,
981+
/// you can use this method to take the value and use it however desired.
982+
/// `Drop` will be invoked on the returned value following normal end-of-scope rules.
983+
///
984+
/// If you have ownership of the container, you can use [`ManuallyDrop::into_inner`] instead.
985+
///
986+
/// # Safety
987+
///
988+
/// This function semantically moves out the contained value without preventing further usage.
989+
/// It is up to the user of this method to ensure that this container is not used again.
990+
#[must_use = "if you don't need the value, you can use `ManuallyDrop::drop` instead"]
991+
#[unstable(feature = "manually_drop_take", issue = "55422")]
992+
#[inline]
993+
pub unsafe fn take(slot: &mut ManuallyDrop<T>) -> T {
994+
ManuallyDrop::into_inner(ptr::read(slot))
995+
}
976996
}
977997

978998
impl<T: ?Sized> ManuallyDrop<T> {

0 commit comments

Comments
 (0)
Please sign in to comment.