Loading tutorials
&T and &mut T, and the difference between String and &str. It explains the problem lifetimes solve. The next chapters cover how to write annotations.6 min read&T and &mut T, and the rule that you may have many shared borrows or one mutable borrow, but not both at once. Here you will learn how the compiler decides how long a borrow lasts. You will also learn why code that look5 min read&T and &mut T, and the difference between String and &str. The previous chapters showed why the compiler rejects dangling references. Here you learn the notation Rust uses to describe how long refer6 min readString and &str. It also assumes you know why the compiler rejects dangling references, which the earlier chapters cover. Here you will learn to write lifetime annotations on functio5 min readimpl blocks, and that you know the basic borrowing rules. It also assumes you have seen a signature like fn longest<'a>(x: &'a str, y: &'a str) -> &'a str. Here you will learn when one lifetime parameter says too much, how to use se5 min readimpl blocks, generics). It also assumes you know the borrowing rules for &T and &mut T, and that you have seen the <'a> syntax from the previous chapters. Here you will learn the three rules the compiler uses to fill in lifeti5 min readString versus &str, and the basics of generics and impl blocks. It also assumes you have seen the 'a syntax on functions. Here you will apply it to struct definitions.4 min readimpl blocks. The main points are where lifetime parameters are declared, how &self changes what elision i4 min read'static lifetime. It assumes you can read lifetime annotations on functions and structs, and that you know ownership, &T and &mut T, String versus &str, and basic generics and trait bounds.6 min readT can be anything, including a reference with a short lifetime. A lifetime bound tells the compiler how long the data inside T must stay valid. This chapter covers the bound forms T: 'a and 'b: 'a, when you must write them, and what T: 'static does and doesn't mean.5 min readT: 'a bounds. A trait object is a value of type dyn Trait used behind a pointer such as 5 min read&T and &mut T, and the basics of lifetime annotations, elision, structs with references, and impl blocks. It does not introduce new syntax. It teaches you to read the compiler's output and pick the right repair.5 min readfor<'a> syntax, the reason it exists, and the places you will meet it. It assumes you can already write functions with explicit lifetime parameters like fn longest<'a>(...). It also assumes you know the elision rules, and that you are comfortable with generic bounds such 5 min read&T versus &mut T, and that you have seen T: 'a bounds. Variance rarely appears in everyday code. It explains why some programs that look safe are rejected, and why a few com5 min read