rustlings

solving rustlings ft. dracuxan
git clone [email protected]:dracuxan/rustlings.git
Log | Files | Refs

iterators1.rs (998B)


      1 // When performing operations on elements within a collection, iterators are
      2 // essential. This module helps you get familiar with the structure of using an
      3 // iterator and how to go through elements within an iterable collection.
      4 
      5 fn main() {
      6     // You can optionally experiment here.
      7 }
      8 
      9 #[cfg(test)]
     10 mod tests {
     11     #[test]
     12     fn iterators() {
     13         let my_fav_fruits = ["banana", "custard apple", "avocado", "peach", "raspberry"];
     14 
     15         // TODO: Create an iterator over the array.
     16         let mut fav_fruits_iterator = todo!();
     17 
     18         assert_eq!(fav_fruits_iterator.next(), Some(&"banana"));
     19         assert_eq!(fav_fruits_iterator.next(), todo!()); // TODO: Replace `todo!()`
     20         assert_eq!(fav_fruits_iterator.next(), Some(&"avocado"));
     21         assert_eq!(fav_fruits_iterator.next(), todo!()); // TODO: Replace `todo!()`
     22         assert_eq!(fav_fruits_iterator.next(), Some(&"raspberry"));
     23         assert_eq!(fav_fruits_iterator.next(), todo!()); // TODO: Replace `todo!()`
     24     }
     25 }