When can a type be covariant
I’ve been descending down a rabbit hole after reading this in the documentation for NonNull:
If you’re not sure if you should useNonNull<T>
, just use*mut T
!
I understand that making your type invariant by default is the safest option, and have read that for an interior mutable type to be sound it must be invariant, but it leaves me with the question: when can a type be covariant? If I am implementing something with NonNull, what should I be considering to determine whether I should allow the type to be covariant? When should a type be invariant?
Source: View source