Skip to content

The PhantomData section is missing clarification or is wrong! #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
eloraiby opened this issue Apr 8, 2020 · 0 comments
Open

The PhantomData section is missing clarification or is wrong! #208

eloraiby opened this issue Apr 8, 2020 · 0 comments
Labels
C-confusing The description is confusing or not clear. C-outdated The description is outdated.

Comments

@eloraiby
Copy link

eloraiby commented Apr 8, 2020

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-confusing The description is confusing or not clear. C-outdated The description is outdated.
Projects
None yet
Development

No branches or pull requests

2 participants