2023-05-29 18:39:08 +01:00
|
|
|
// 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 12:57:01 +01:00
|
|
|
//
|
2023-05-29 18:39:08 +01:00
|
|
|
// Make me compile by filling in the `???`s
|
2020-08-04 12:57:01 +01:00
|
|
|
|
2023-02-24 13:51:03 +00:00
|
|
|
fn main() {
|
2024-04-17 22:34:27 +01:00
|
|
|
// You can optionally experiment here.
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn iterators() {
|
|
|
|
let my_fav_fruits = vec!["banana", "custard apple", "avocado", "peach", "raspberry"];
|
2020-08-04 12:57:01 +01:00
|
|
|
|
2024-04-17 22:34:27 +01:00
|
|
|
let mut my_iterable_fav_fruits = ???; // TODO: Step 1
|
2020-08-04 12:57:01 +01:00
|
|
|
|
2024-04-17 22:34:27 +01:00
|
|
|
assert_eq!(my_iterable_fav_fruits.next(), Some(&"banana"));
|
|
|
|
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 2
|
|
|
|
assert_eq!(my_iterable_fav_fruits.next(), Some(&"avocado"));
|
|
|
|
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 3
|
|
|
|
assert_eq!(my_iterable_fav_fruits.next(), Some(&"raspberry"));
|
|
|
|
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 4
|
|
|
|
}
|
2020-08-04 12:57:01 +01:00
|
|
|
}
|