Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upPhantomData is incomprehensible #22914
Comments
kmcallister
added
the
A-docs
label
Mar 1, 2015
This comment has been minimized.
This comment has been minimized.
|
If you have a lifetime, and the type is acting like a reference, then In any case, the major motivation for |
This comment has been minimized.
This comment has been minimized.
|
I see you've used lifetime as part of BTW: the first paragraph in your comment is already clearer to me than the documentation :) |
This comment has been minimized.
This comment has been minimized.
|
The rustbyexample example seems relevant. A previous example was referenced at the mozilla research blog though I think rustbyexample is clearer. Note that the syntax of this example has changed recently. That If indeed what you need is something similar, you should flag it on rustbyexample for a more practical example. @huonw I was only aware of using phantom types in for use cases like unit system manipulation and such. If you can provide the gist of what other things they can be used for I can probably shoehorn it into an rustbyexample example(s) (there's IRC if I get stuck). Though I don't know when I'd get to it. |
This comment has been minimized.
This comment has been minimized.
|
@mdinger Almost instances of phantom types for dimensional analysis won't care about the precise variance (unlike unsafe/low-level code) and so just need to make the compiler shut up. :) |
This comment has been minimized.
This comment has been minimized.
|
@pornel great that you've made progress! |
This comment has been minimized.
This comment has been minimized.
|
Okay. The distinction between them is definitely unclear then too (in the docs). |
This comment has been minimized.
This comment has been minimized.
|
If it's just to make the compiler shut up, then it's a good indication that the old default was better (not needing PhantomData for most unused type parameters). |
This comment has been minimized.
This comment has been minimized.
alexchandel
commented
Mar 2, 2015
|
@pornel I sympathize. PhantomData and PhantomFn are Byzantine to me as well, and I'm hitting several issues in rlibc because of them. |
This comment has been minimized.
This comment has been minimized.
|
@bluss That bit me, because unused parameter did absolutely nothing, even when I used a parameter with the same name a method. I don't mind having a marker, I just needed to learn how to use it. |
This comment has been minimized.
This comment has been minimized.
To be clear, it is just the use of 'unused' type parameters for dimensional analysis/tagging where the details of the precise |
kornelski commentedMar 1, 2015
I need to give a Rust slice to a C API that will return an opaque handle (that actually contains a pointer to the slice), and the slice must outlive the handle.
rustcnicely suggested usingPhantomDatafor this, but the description of phantom data (and its RFC) for me is so far removed from my mental model/terminology of the problem, that it sounds like git man pages to me.The RFC is even worse, since it uses type variance terminology which is so confusing, that the most comprehensible description of them on Wikipedia is a 3D cube!