rustlings/exercises/iterators/iterators1.rs

23 lines
938 B
Rust
Raw Normal View History

2020-08-04 06:57:01 -05:00
// iterators1.rs
//
2020-08-04 06:57:01 -05:00
// Make me compile by filling in the `???`s
//
// 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
2020-08-04 06:57:01 -05:00
// how to go through elements within an iterable collection.
//
2022-07-14 11:29:09 -05:00
// Execute `rustlings hint iterators1` or use the `hint` watch subcommand for a hint.
2020-08-04 06:57:01 -05:00
fn main () {
let my_fav_fruits = vec!["banana", "custard apple", "avocado", "peach", "raspberry"];
2023-03-10 15:19:05 -06:00
let mut my_iterable_fav_fruits = my_fav_fruits.iter();
2020-08-04 06:57:01 -05:00
assert_eq!(my_iterable_fav_fruits.next(), Some(&"banana"));
2023-03-10 15:19:05 -06:00
assert_eq!(my_iterable_fav_fruits.next(), Some(&"custard apple"));
2020-08-04 06:57:01 -05:00
assert_eq!(my_iterable_fav_fruits.next(), Some(&"avocado"));
2023-03-10 15:19:05 -06:00
assert_eq!(my_iterable_fav_fruits.next(), Some(&"peach"));
assert_eq!(my_iterable_fav_fruits.next(), Some(&"raspberry"));
2023-03-10 15:19:05 -06:00
assert_eq!(my_iterable_fav_fruits.next(), None);
2020-08-04 06:57:01 -05:00
}