How does it work PhantomDatain Rust? Nomicon says the following:
In order to tell dropck that we have eigenvalues of type T, and therefore can discard some Ts when falling, we must add an additional PhantomData that says just that.
It seems to me that when adding a field PhantomDatato the structure, say, in the case Vec.
pub struct Vec<T> {
data: *mut T,
length: usize,
capacity: usize,
phantom: PhantomData<T>,
}
so that the reset controller prohibits the following code sequence:
fn main() -> () {
let mut vector = Vec::new();
let x = Box::new(1 as i32);
let y = Box::new(2 as i32);
let z = Box::new(3 as i32);
vector.push(x);
vector.push(y);
vector.push(z);
}
Since the release x, yand zwill happen to the release Vec, I expect some complaints from the compiler. However, if you run the above code, there are no warnings or errors.
Novus