What's the different between PhantomData<Box<Node<T>>> and PhantomData<T>

Viewed 156

Rust LinkedList contains one marker field: PhantomData<Box<Node<T>>>.

pub struct LinkedList<T> {
   head: Option<NonNull<Node<T>>>,
   tail: Option<NonNull<Node<T>>>,
   len: usize,
   marker: PhantomData<Box<Node<T>>>,
}

struct Node<T> { 
  next: Option<NonNull<Node<T>>>, 
  prev: Option<NonNull<Node<T>>>, 
  element: T, 
}

From https://doc.rust-lang.org/nomicon/phantom-data.html. PhantomData is for two purpose: variance & dropchk.

I already read https://rust-lang.github.io/rfcs/0769-sound-generic-drop.html and https://rust-lang.github.io/rfcs/1238-nonparametric-dropck.html, but did not fully understand it.

What's the differece between PhantomData<Box<Node<T>>>, PhantomData<Node<T>> and PhantomData<T>?

0 Answers
Related