When can a type be covariant

PressRex profile image
by PressRex
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 use NonNull<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

PressRex profile image
by PressRex

Subscribe to New Posts

Lorem ultrices malesuada sapien amet pulvinar quis. Feugiat etiam ullamcorper pharetra vitae nibh enim vel.

Success! Now Check Your Email

To complete Subscribe, click the confirmation link in your inbox. If it doesn’t arrive within 3 minutes, check your spam folder.

Ok, Thanks

Read More