March 2018
Intermediate to advanced
272 pages
7h 4m
English
Let's start with the most simple method. The basic method for the rest to work is the next() method. This function will return either the next element in the iteration or a None if the iterator has been consumed. This can be used to manually get the next element, or to create a for using a while, for example:
let arr = [10u8, 14, 5, 76, 84];let mut iter = arr.iter();while let Some(elm) = iter.next() { println!("{}", elm);}
That would be the same as this:
let arr = [10u8, 14, 5, 76, 84];for elm in &arr { println!("{}", elm);}
Read now
Unlock full access