Warning
This post was published 67 days ago. The information described in this article may have changed.
Currently if you want to express your typeโs variance with respect to generic parameter, perhaps with a generic lifetime parameter 'a
, you have to include a PhantomData
field with something like &'a T
, fn(&'a T)
, or fn(T) -> T
. These are pretty โmagicalโ and require a fair amount of reasoning to determine why they're correct.
Why doesn't Rust just have (say) PhantomCovariant<T>
, PhantomContravariant<T>
, and PhantomInvariant<T>
, so that you could replace e.g. PhantomData<fn(T) -> T>
with the much clearer PhantomInvariant<T>
? (These would simply be defined in terms of PhantomData
.) This would be more explicit, less magical.
2 posts - 2 participants
๐ท๏ธ rust_feed