5/5
# Iterator adaptors ## Example Execute the following command to run [`./solutions/examples/iter_adaptors.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/iterator_adaptors/solutions/examples/iter_adaptors.rs) ```shell cargo run --example iter_adaptors ``` ## Exercises Exercises are in [`./exercises/src/lib.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/iterator_adaptors/exercises/src/lib.rs) ### Exercise 1 ```rust pub fn filter_non_zero(v: Vec<u32>) -> Vec<u32> { todo!(); } ``` Return a vector where each element is greater than 0. ### Exercise 2 ```rust pub fn to_string(v: Vec<&str>) -> Vec<String> { todo!(); } ``` Convert vector of `&str` into a vector of `String`. ### Exercise 3 ```rust pub fn to_hash_map(v: Vec<(String, u32)>) -> HashMap<String, u32> { todo!(); } ``` Convert a vector of `(String, u32)` into a `HashMap<String, u32>`. ## Test ```shell cargo test ```
Execute the following command to run ./solutions/examples/iter_adaptors.rs
Exercises are in ./exercises/src/lib.rs
Return a vector where each element is greater than 0.
Convert vector of &str
into a vector of String
.
Convert a vector of (String, u32)
into a HashMap<String, u32>
.
An empowering guide to Iterator adaptors - Learn to harness Rust's iterator adaptors to chain operations, transforming data with methods like `filter` and `map`, and gathering results with `collect`. Solidify your understanding by implementing functions to filter numeric vectors, convert string types, and construct HashMaps.
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