Loading tutorials
Iterator in for loops.2 min readT: Display. Here you will learn two ways to restrict an associated type: fix it to one concrete type, or require it to implement traits.2 min readT: Display, and run a for loop over an iterator. You have used associated types every time you called .map() or wrote a + b. Here you will see where they sit in two standard library traits and how to cons2 min readT: Trait, and have seen Iterator with for loops. Here you will learn how to choose between two ways of letting a trait mention another type.2 min readtype Item;, and that you can read generic bounds like T: Iterator. It covers the three ways to name an associated type and when each one is required.2 min readIterator<Item = T>, and use Box<T> for heap values. It covers what changes when you use such a trait as a trait object.2 min readIterator::next works, and you understand shared versus mutable borrows and basic lifetime annotations. It explains why a plain associated type cannot express one kind of iterator. The next chapters give the fix.2 min readtype Item;), read where clauses, and use lifetime annotations such as &'a self. It covers the syntax only. The next chapters use it for lending iterators and type families.2 min readIterator. It builds on the previous chapters' generic associated type syntax.2 min readT: 'a. It explains the where Self: 'a clause that the compiler requires on that GAT.3 min readwhere clauses. It also assumes you know what Rc<T> and Box<T> do. Earlier chapters used GATs with a lifetime parameter. Here the GAT takes a type parameter.2 min readwhere Self: 'a clause. Generic associated types (GATs) have been stable since Rust 1.65. They solve real problems, but they cost something in flexibility and in error-message clarity.3 min read