2020-08-04 11:57:01 +00:00
|
|
|
// iterators1.rs
|
2021-05-12 15:20:07 +00:00
|
|
|
//
|
2023-05-29 17:39:08 +00: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 11:57:01 +00:00
|
|
|
//
|
2023-05-29 17:39:08 +00:00
|
|
|
// Make me compile by filling in the `???`s
|
2021-05-12 15:20:07 +00:00
|
|
|
//
|
2023-05-29 17:39:08 +00:00
|
|
|
// Execute `rustlings hint iterators1` or use the `hint` watch subcommand for a
|
|
|
|
// hint.
|
2020-08-04 11:57:01 +00:00
|
|
|
|
|
|
|
|
2023-08-26 23:06:01 +00:00
|
|
|
#[test]
|
2023-02-24 13:51:03 +00:00
|
|
|
fn main() {
|
2020-08-04 11:57:01 +00:00
|
|
|
let my_fav_fruits = vec!["banana", "custard apple", "avocado", "peach", "raspberry"];
|
|
|
|
|
2024-02-10 17:36:11 +00:00
|
|
|
let mut my_iterable_fav_fruits = my_fav_fruits.iter(); // TODO: Step 1
|
2020-08-04 11:57:01 +00:00
|
|
|
|
|
|
|
assert_eq!(my_iterable_fav_fruits.next(), Some(&"banana"));
|
2024-02-10 17:36:11 +00:00
|
|
|
assert_eq!(my_iterable_fav_fruits.next(), Some(&"custard apple")); // TODO: Step 2
|
2020-08-04 11:57:01 +00:00
|
|
|
assert_eq!(my_iterable_fav_fruits.next(), Some(&"avocado"));
|
2024-02-10 17:36:11 +00:00
|
|
|
assert_eq!(my_iterable_fav_fruits.next(), Some(&"peach"));// TODO: Step 3
|
2022-03-30 11:27:52 +00:00
|
|
|
assert_eq!(my_iterable_fav_fruits.next(), Some(&"raspberry"));
|
2024-02-10 17:36:11 +00:00
|
|
|
assert_eq!(my_iterable_fav_fruits.next(), None); // TODO: Step 4
|
2020-08-04 11:57:01 +00:00
|
|
|
}
|