5/5
# Generic trait ## Example Execute the following command to run [`./solutions/examples/generic_trait.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/generic_trait/solutions/examples/generic_trait.rs) ```shell cargo run --example generic_trait ``` ## Exercises Exercises are in [`./exercises/src/lib.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/generic_trait/exercises/src/lib.rs) ### Exercise 1 ```rust impl<T> Iterator<T> for TupleIter<T> { fn next(&mut self) -> Option<&T> { todo!(); } } ``` Implement the `Iterator` trait for `TupleIter<T>`. Return the next element in the tuple until all elements are iterated. ### Exercise 2 Implement the `Iterator` trait for `VecIter<T>`. Return the next element in the vector until all elements are iterated. ## Test ```shell cargo test ```
Execute the following command to run ./solutions/examples/generic_trait.rs
Exercises are in ./exercises/src/lib.rs
Implement the Iterator
trait for TupleIter<T>
.
Return the next element in the tuple until all elements are iterated.
Implement the Iterator
trait for VecIter<T>
.
Return the next element in the vector until all elements are iterated.
A hands-on exploration of Generic trait - Unlock the power of Rust's generic traits by implementing the versatile `Iterator` trait. Apply your skills to build custom iterators for tuple and vector structures, making your data types iterable.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Introduction to the Rust programming language
Rust variables and functions
Scalar types, arrays, strings, enum, structs, vectors, and hash maps in Rust
Rust control flows: If / else, if let and let else, loop, match
Rust ownership, including borrow and references
Rust error handling
Rust Modules
Rust Traits
Last updated on July 11, 2025
Rust Developer
Rust Programming BasicsDuration: 6min
Duration: 18min
Duration: 47min
Duration: 15min
Duration: 19min
Duration: 8min
Duration: 12min
Duration: 46min
Duration: 14min
Course Overview
About the course
Introduction to the Rust programming language
Rust variables and functions
Scalar types, arrays, strings, enum, structs, vectors, and hash maps in Rust
Rust control flows: If / else, if let and let else, loop, match
Rust ownership, including borrow and references
Rust error handling
Rust Modules
Rust Traits
Last updated on July 11, 2025