1
0
Fork 0
mirror of https://github.com/notohh/rustlings.git synced 2024-12-21 16:08:09 -05:00
rustlings/exercises/18_iterators/iterators1.rs

26 lines
998 B
Rust
Raw Normal View History

// When performing operations on elements within a collection, iterators are
// essential. This module helps you get familiar with the structure of using an
// iterator and how to go through elements within an iterable collection.
2020-08-04 07:57:01 -04:00
fn main() {
2024-04-17 17:34:27 -04:00
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
#[test]
fn iterators() {
2024-06-27 20:07:56 -04:00
let my_fav_fruits = ["banana", "custard apple", "avocado", "peach", "raspberry"];
2020-08-04 07:57:01 -04:00
2024-06-27 20:07:56 -04:00
// TODO: Create an iterator over the array.
2024-06-27 20:26:35 -04:00
let mut fav_fruits_iterator = todo!();
2020-08-04 07:57:01 -04:00
2024-06-27 20:07:56 -04:00
assert_eq!(fav_fruits_iterator.next(), Some(&"banana"));
2024-06-27 20:26:35 -04:00
assert_eq!(fav_fruits_iterator.next(), todo!()); // TODO: Replace `todo!()`
2024-06-27 20:07:56 -04:00
assert_eq!(fav_fruits_iterator.next(), Some(&"avocado"));
2024-06-27 20:26:35 -04:00
assert_eq!(fav_fruits_iterator.next(), todo!()); // TODO: Replace `todo!()`
2024-06-27 20:07:56 -04:00
assert_eq!(fav_fruits_iterator.next(), Some(&"raspberry"));
2024-06-27 20:26:35 -04:00
assert_eq!(fav_fruits_iterator.next(), todo!()); // TODO: Replace `todo!()`
2024-04-17 17:34:27 -04:00
}
2020-08-04 07:57:01 -04:00
}