std-method

Recover ownership from ManuallyDrop

ManuallyDrop suppresses automatic destruction, but it does not permit invalid values. Consuming the wrapper is the simple way to restore ordinary ownership when the wrapper still contains its live value. Expected stdout (not executed): report Common mistake: Treating ManuallyDrop as a substitute for uninitialized storage.

Formal Syntax & Structure

rust syntaxrust
ManuallyDrop::into_inner(wrapper)

Working Example

Example Snippetrust
#![deny(unsafe_op_in_unsafe_fn)]fn main() {    use std::mem::ManuallyDrop;    let parked = ManuallyDrop::new(String::from("report"));    let owned = ManuallyDrop::into_inner(parked);    println!("{owned}");}
Rust Reference