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