If there was a &write_only T
type, would it be contravariant with respect to T
? The reason why I think it would be is that it seems like it would always be fine to write a &'long T
to a location of type &'short T
is required.
Yes I believe it could be contravariant w. r. t. T
. But it would have to be truly write-only, so no destructor calls for T
either; in terms of API design, this could be achieved for example by only allowing T: Copy
; or giving it some (very clearly documented) leaking properties.
Maybe &mut MaybeUninit<T>
may be something like this? It is safe to write to it, but unsafe to read.