PhantomData
Rust PhantomData
is useful to tell compilers that I own a certain value despite having a raw pointer in it:
use std::marker;
struct Foo<'a, T: 'a> {
bar: *const T,
_marker: marker::PhantomData<&'a T>,
}
It is also useful to tell the compiler that a type does not implement [[Rust Send and Sync|the Send
or Sync
traits]]:
pub type PhantomUnsync = PhantomData<Cell<()>>;
pub type PhantomUnsend = PhantomData<MutexGuard<'static, ()>>;