Closed
Description
Reads the value from
src
without dropping it.
But in fact this code does run the destructor:
use std::{ptr, mem};
struct Foo;
impl Drop for Foo {
fn drop(&mut self) {
println!("drop day");
}
}
fn main() {
let x = Foo;
unsafe {
ptr::read(&x as *const Foo);
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.
Metadata
Metadata
Assignees
Labels
No labels