Prompted by all of the Drop discussion, and quoting @scottmcm’s implementation.
If there aren’t any objections, suggestions, or corrections, I’ll probably open a PR with this. It seems like a small but useful addition. I’m primarily interested in suggestions for wording of the docs.
impl<T> ManuallyDrop<T> {
/// Take the contained value out.
///
/// 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 normally at end of scope, as with all other owned values.
///
/// If you have ownership of the value, you can use `ManuallyDrop::into_inner` instead.
///
/// # 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.
pub unsafe fn take(slot: &mut ManuallyDrop<T>) -> T {
ManuallyDrop::into_inner(ptr::read(slot))
}
}