[−][src]Type Definition phantasm::Covariant
type Covariant<T: ?Sized> = Covariant<T>;
Marker zst type that is covariant over T
.
"Covariant" means that given F<_>
, Super
and Sub
(where Sub
is a
subtype of Super
), F<Sub>
is a subtype of F<Super>
(but F<Super>
is not a subtype of F<Sub>
)
Examples
// This struct is covariant over `T` struct Test<T>(phantasm::Covariant<T> /* ... */); let _: Test<i32> = Test(phantasm::Covariant); let _ = Test(phantasm::Covariant::<i32>);
ⓘThis example deliberately fails to compile
use phantasm::Covariant; // `F<Super>` is **not** a subtype of `F<Sub>` fn fail<'l>(arg: Covariant<&'l ()>) -> Covariant<&'static ()> { arg }
use phantasm::Covariant; // `F<Sub>` **is** a subtype of `F<Super>` fn pass<'l>(arg: Covariant<&'static ()>) -> Covariant<&'l ()> { arg }
See also
- crate docs
PhantomData
- Subtyping and Variance nomicon chapter