nomicon: Mention contravariance

pull/10/head
Ulrik Sverdrup 9 years ago committed by Manish Goregaokar
parent 9a11f6e3ff
commit ef1cd4dd45

@ -44,10 +44,11 @@ subtyping of its outputs. There are two kinds of variance in Rust:
* F is *invariant* over `T` otherwise (no subtyping relation can be derived) * F is *invariant* over `T` otherwise (no subtyping relation can be derived)
(For those of you who are familiar with variance from other languages, what we (For those of you who are familiar with variance from other languages, what we
refer to as "just" variance is in fact *covariance*. Rust does not have refer to as "just" variance is in fact *covariance*. Rust has *contravariance*
contravariance. Historically Rust did have some contravariance but it was for functions. The future of contravariance is uncertain and it may be
scrapped due to poor interactions with other features. If you experience scrapped. For now, `fn(T)` is contravariant in `T`, which is used in matching
contravariance in Rust call your local compiler developer for medical advice.) methods in trait implementations to the trait definition. Traits don't have
inferred variance, so `Fn(T)` is invariant in `T`).
Some important variances: Some important variances:

Loading…
Cancel
Save