Loading tutorials
Iterator with for loops and adapters. You should also have read the previous chapter on declaring and implementing associated types. Here you learn how to put conditions on an associated 5 min readfor loop or added two values with +. This chapter looks at the two most common ones, Iterator::Item and Add::Output. It shows how to read their signatures, bound them in your own functions, and avoid the errors they usually cause.6 min readT: Display, and have seen Iterator with its Item type. You do not need lifetimes beyond the basics.5 min readtype Item;. It covers the ways to write the name of an associated type, when each one works, and what to do when the compiler says a name is ambiguous.5 min readBox<dyn Trait> for simple traits. You should also know how to declare an associated type and constrain it as in I: Iterator<Item = u32>. Here you will learn what changes when a trait with associated types is5 min readItem is not expressive enough. You need to be comfortable with Iterator, associated types as covered earlier in this tutorial, and lifetime elision on &mut self methods.5 min readtype Item;. It also assumes you know basic lifetime annotations and generic bounds. GATs were stabilized in Rust 1.65, so any current toolchain accepts the code 5 min readIterator<Item = T> bounds, and follow basic borrowing and lifetime rules. You will build a lending iterator, a trait whose items borrow from the iterator itself. You will also see why the where Self: 'a clause is required.5 min readwhere Self: 'a clause that nearly every generic associated type (GAT) with a lifetime parameter carries. It assumes you can read the lending iterator from the previous chapter: a trait with type Item<'a> and a next method that takes &'a mut self. It also assumes you5 min readRc, Box, and the Deref trait. Here the GAT takes a type parameter instead of a lifetime, which lets a trait describe a whole fa6 min read