Updated Question:
Or I can ask this way: for every type T
, if it's Copy
, then there is no way for it to be moved, right? I mean is there any way like the std::move
in C++ can move a copyable value explicitly?
Original Question:
Presume we have below a piece of Rust code, in this code, I defined a variable x
holding an i32 value. What I want to do is to drop its value and invalidate it. I tried to use ptr::drop_in_place
to drop it through a pointer, but it doesn't work, why?
fn main() {
let mut x = 10;
use std::ptr;
unsafe {
ptr::drop_in_place(&mut x as *mut i32);
}
println!("{}", x); // x is still accessible here.
}