Struct std::kinds::marker::InvariantTypeExperimental
[-]
[+]
[src]
pub struct InvariantType<T>;
A marker type whose type parameter T
is considered to be
invariant with respect to the type itself. This is (typically)
used to indicate that instances of the type T
may be read or
written, even though that may not be apparent.
For more information about variance, refer to this Wikipedia article http://en.wikipedia.org/wiki/Variance_%28computer_science%29.
Example
The Cell type is an example which uses unsafe code to achieve "interior" mutability:
pub struct Cell<T> { value: T } fn main() {}pub struct Cell<T> { value: T }
The type system would infer that value
is only read here and
never written, but in fact Cell
uses unsafe code to achieve
interior mutability.