-
Notifications
You must be signed in to change notification settings - Fork 295
Open
Labels
C-confusingThe description is confusing or not clear.The description is confusing or not clear.C-outdatedThe description is outdated.The description is outdated.
Description
In the book:
In order to tell dropck that we do own values of type T, and therefore may drop some T's when we drop, we must add an extra PhantomData saying exactly that
however:
#[repr(C)]
pub struct Unique<T> {
ptr : *mut T,
_marker : ::core::marker::PhantomData<T>,
}
impl<T> Unique<T> {
pub fn new(ptr: *mut T) -> Self { Self { ptr : ptr, _marker: ::core::marker::PhantomData } }
pub fn getMutPtr(&mut self) -> *mut T { self.ptr }
pub fn getPtr(&self) -> *const T { self.ptr }
}
#[repr(C)]
pub struct Vec<T> {
elements : Unique<T>,
count : usize,
capacity : usize,
}
...
Will compile and Vec<T>
can be used and dropped without any problem. So, what's the point of PhantomData there ? unless I implement Drop
on Vec
the code with or without PhantomData
will compile just fine!
Metadata
Metadata
Assignees
Labels
C-confusingThe description is confusing or not clear.The description is confusing or not clear.C-outdatedThe description is outdated.The description is outdated.