Can Rust consume an iterator passed into a function?
<p>I'm trying to implement a simple REPL calculator in Rust and I'm hitting brick walls all over the place. </p>

<p>I'm consuming chars while iterating over a hardcoded string. When I hit a numeric character I want to pass control over to a function that will consume the rest of the number (assuming the number has more than one digit) and return the number, converted to an Integer.</p>

<p>I'm having trouble with passing <code>Chars</code> iterator to a function. The error I'm getting is <code>use of moved value: 'iter'</code>.</p>

<p>I understand that I can't mutate something that I gave to someone else - something that had its ownership moved - but I don't know any other way of doing this, especially since the Chars iterator is non-copyable.</p>

<pre><code>#[derive(Clone, Debug)]
enum Token {
    Addition,
    Substraction,
    Multiplication,
    Division,
    Integer(i32),
    Error,
}

fn consume_number(mut iter: std::str::Chars) -&gt; Option&lt;i32&gt; {
    while let Some(item) = iter.next() {
        println!("{:?}", item);
    }

    return Some(1337);
}

fn tokenize(line: &amp;str) -&gt; Vec&lt;Token&gt; {
    let mut iter = line.chars();
    let mut tokens = Vec::new();
    let mut token;

    while let Some(c) = iter.next() {
        if c.is_whitespace() { continue };

        if c.is_digit(10) {
            token = match consume_number(iter) {
                Some(i32) =&gt; Token::Integer(i32),
                None =&gt; Token::Error,
            };
        } else {
            token = match c {
                '+'                    =&gt; Token::Addition,
                '-'                    =&gt; Token::Substraction,
                '*'                    =&gt; Token::Multiplication,
                '/'                    =&gt; Token::Division,
                _                      =&gt; Token::Error,
            };
        };
        tokens.push(token);
    }
    return tokens;
}



fn main() {
    let line = "631 * 32 + 212 - 15 / 89";
    println!("{:?}", tokenize(&amp;line));
}
</code></pre>