Loading tutorials
'long: 'short means "'long outlives 'short". The previous chapter showed that a longer lifetime can stand in for a shorter one. This chapter ask2 min read'long: 'short) and lifetime subtyping. Here we apply that to the most common kind of variance.2 min read&'long T could be used where &'short T was expected. Invariance is the case where that substitution is forbidden.2 min read'long: 'short as "'long outlives 'short".2 min read&mut T and Cell<T> are invariant. Here you will see how the compiler works out the variance of your own structs and enums.2 min read&'a T is covariant in 'a, and &mut T and Cell<T> are invariant in T.2 min readFn traits. It also assumes you know that a longer lifetime can stand in for a shorter one, from the earlier chapters on subtyping.2 min readFn traits. The previous chapter showed that a lifetime parameter chosen by the caller is sometimes too rigid. Here you learn the syntax that fixes it.2 min readFn, FnMut and FnOnce traits. The previous chapter introduced for<'a>. Here you will see where it hides in everyday code.2 min readFn traits and the for<'a> syntax from the previous chapters.2 min readFn(&T) -> &U sugar from the previous chapters. Higher-ranked bounds also appear on traits that have nothing to do with closures. The most common case is a bound on a reference to a generic type.2 min readfor<'a> bounds and know that fn(T) is contravariant in T. It adds one more subtyping rule: a higher-ranked type is a subtype of each of its less general forms.2 min readFn bounds, and the variance rules from the earlier chapters. It shows how to read the lifetime errors those features cause and how to fix them.2 min readfor<'a> bounds, the Iterator trait, and how &mut borrows work. It shows a problem that higher-ranked bounds cannot solve and the feature that does.2 min read