Loading tutorials
&T and &mut T, and the difference between String and &str. It covers one idea: why the compiler tracks how long a reference stays valid, and what it rejects.3 min read&T and &mut T. It also assumes you have seen the dangling reference error E0597 from the previous chapter. Here you will learn how the compiler decides how long a borrow lasts, and why that is shorter than you might expect.3 min read&T and &mut T, and the difference between String and &str. You have already seen why the compiler rejects dangling references. Here you learn the syntax that lets you describe reference relationships to the c3 min read&T and &mut T, and the difference between String and &str. It also assumes you have seen the 'a annotation syntax. Here you will apply it to functions that return references.2 min readlongest<'a>, and that you understand the borrowing rules for &T and &mut T. It covers when one lifetime is not enough and how to choose between one shared lifetime and several separate ones.2 min read&'a str and know why longest<'a> needs one. Here you learn the three rules the compiler applies to fill in lifetimes you did not write.2 min read&T and &mut T, and the difference between String and &str. You should also have read the earlier chapters on lifetime annotation syntax and function signatures.2 min readimpl blocks, and generics. It also assumes you know the borrowing rules and the elision rules for functions. Here you will see how a struct's lifetime parameter reaches its methods, and how to pick which lifetime a method returns.2 min read&'a str, and that you know what a generic bound such as T: Debug means.2 min read'a annotations on functions and structs. It covers what T: 'a means and when you need to write it.2 min read'static lifetime, and generic bounds like T: 'a. Here you will see how lifetimes attach to trait objects, and why closures that capture references need them.2 min read'a from earlier chapters. Here you learn to read the three most common lifetime errors and pick a fix for each.2 min readFn closures are, and understand where clauses. Higher-ranked trait bounds (HRTBs) are rarely written by hand. You need them when a closure must accept a reference whose lifetime the callee picks, not the caller.3 min read&T and &mut T, and you have seen compiler errors such as E0597. Variance explains a few cases where the compiler accepts or rejects lifetime code that otherwise looks surprising.2 min read