You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use std::{ptr, mem};structFoo;implDropforFoo{fndrop(&mutself){println!("drop day");}}fnmain(){let x = Foo;unsafe{
ptr::read(&x as*constFoo);
mem::forget(x);}}
It's not clear what "without dropping it" means. I suspect the point is that it won't mark the target (hence *const T) as destroyed, from an era when this was more of a dynamic notion than today. But at any rate, the docs should reflect reality. As far as I know this is the way to explicitly run a destructor in Rust — a nice duality because ptr::write is the "placement new" for uninitialized memory.
The text was updated successfully, but these errors were encountered:
But in fact this code does run the destructor:
It's not clear what "without dropping it" means. I suspect the point is that it won't mark the target (hence
*const T
) as destroyed, from an era when this was more of a dynamic notion than today. But at any rate, the docs should reflect reality. As far as I know this is the way to explicitly run a destructor in Rust — a nice duality becauseptr::write
is the "placement new" for uninitialized memory.The text was updated successfully, but these errors were encountered: