Loading tutorials
'long: 'short written as an outlives bound. Here we define variance and set up the vocabulary. The next chapters take covariance5 min read'long: 'short ("'long outlives 'short") means. It builds on the previous chapters on outlives bounds and lifetime subtyping. Here you will see the most common form of variance, covari5 min read&'long T can be used where &'short T is expected. Here you will see where that substitutio5 min read'long: 'short means 'long outlives 'short. It also assumes you can read function pointer types such as fn(&str) -> usize.4 min read&'a T is covariant, &mut T is invariant in T, and function arguments run the other way. This chapter covers how the compiler works out the variance of types you define yourself. It assumes you know generics, basic lifetime annotations on structs, and the covariant,4 min readfor<'a> bounds. Here you will learn how to use PhantomData to set the variance of your own types.3 min readFn traits. It shows one concrete failure of a named lifetime parameter and explains why the failure is unavoidable. The next chapter introduces the syntax that fixes i5 min readfor<'a> syntax: what it quantifies, where it can appear, and how to read it. It assumes you know basic lifetime annotations, generics with trait bounds, and the Fn traits. It also assumes you have seen why a single lifetime parameter is not enough for a callback that mu4 min readFn, FnMut and FnOnce traits. You have seen that for<'a> lets a bound hold for every lifetime. Here you learn that you rarely type it, because the compiler inserts it for you.4 min readfor<'a> Fn(&'a str) -> &'a str and know that Fn(&str) -> &str expands to that form. It covers how the compiler decides whether a closure is higher-ranked, and why the same closure can compile in one position and fail in another.4 min readfor<'a> syntax and the Fn(&T) -> &U sugar from the earlier chapters. It also assumes you are comfortable with generics, trait bounds and IntoIterator. Here you will use the same idea on a trait that has nothing to do with closures.5 min readfor<'a> syntax. You should know that 'long: 'short means 'long outlives 'short, and that a longer lifetime can stand in for a shorter one. Here we apply those ideas to types that contain a 5 min readFn, FnMut and FnOnce traits. It also builds on the earlier chapters on variance and for<'a>. Here you will learn to read the errors those features produce, work out the caus5 min readfor<'a> cannot solve and the feature that solves it. You should already know how Iterator works. You should also have read the earlier chapters on for<'a> bounds and on variance, and you should be comfortable with where clauses and associated types.4 min read