-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
PhantomData is incomprehensible #22914
Comments
If you have a lifetime, and the type is acting like a reference, then In any case, the major motivation for |
I see you've used lifetime as part of BTW: the first paragraph in your comment is already clearer to me than the documentation :) |
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. |
@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. :) |
@pornel great that you've made progress! |
Okay. The distinction between them is definitely unclear then too (in the docs). |
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). |
@pornel I sympathize. PhantomData and PhantomFn are Byzantine to me as well, and I'm hitting several issues in rlibc because of them. |
@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. |
To be clear, it is just the use of 'unused' type parameters for dimensional analysis/tagging where the details of the precise |
Fixes rust-lang#22914 Said issue was mostly fixed, as there wasn't any examples when it was initially posted. This is mostly just some re-wording of some things and some cleanup
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.
rustc
nicely suggested usingPhantomData
for 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!
The text was updated successfully, but these errors were encountered: