I\'m iterating through an array, and depending on the current value, I\'d like to pass the iterator to a sub function and have it deal with a number of values, and upon exit
The for
construct consumes the iterator, and doing what you want using it will be quite tricky (if not impossible, I'm really not sure about that).
However, you can have it working pretty easily by switching to a while let
construct, like this:
fn parse_tokens (tokens: &Vec<char>) {
let mut iter = tokens.iter();
let mut things: Vec<Thing> = vec![];
while let Some(token) = iter.next() {
match token {
&'a' => things.push(take_three(&mut iter)),
&'b' => things.push(take_four(&mut iter)),
_ => {},
}
}
}