I just discovered what `PhantomData` is for

62 points SpencerTheBeigest

I'm writing a text buffer that uses an Index type to remember where in the text something was. I wanted to be able to "attach" the Index type to the borrow checker to assure, at compile-time, that the Index is still valid. Turns out that's exactly what PhantomData is.

I swear, everytime I think I have some extremely niche, unanswerable need, I find out that the Rust std library already has a really nice solution (with documentation) for it. This is why so many people are so passionate about this language.