Avatar ·

How to implement Iterator and IntoIterator traits for a simple structure in Rust?

Hello everyone! I started learning Rust and encountered a problem when implementing custom iterators. I have a simple structure `BookCollection` that stores a list of books. I want this structure to be usable in a `for` loop and also passable to functions that expect iterators. But the compiler gives errors. Here is my code: ```rust struct Book { title: String, author: String, } struct BookCollection { books: Vec, } impl BookCollection { fn new() -> Self { BookCollection { books: Vec::new() } } fn add_book(&mut self, book: Book) { self.books.push(book); } } fn main() { let mut collection = BookCollection::new(); collection.add_book(Book { title: "1984".to_string(), author: "Orwell".to_str