Looking at this approach to looking ahead in a token stream, which boils down to
use proc_macro2::token_stream::IntoIter;
fn foo(rest: &mut IntoIter) {
let mut peek = rest.clone();
match (peek.next(), peek.next()) { ... }
}
which, with explicit reborrowing and type annotations becomes (IIANM)
use proc_macro2::token_stream::IntoIter;
fn foo(rest: &mut IntoIter) {
let mut peek: IntoIter = (&*rest).clone();
match ((&mut peek).next(), (&mut peek).next()) { ... }
}
I trust that this does not clone the whole token stream, rather merely something that is effectively a cursor. But the details of how this is done are not clear to me. I guess I don't understand how lazy traversal and/or holding in memory of the token stream itself is implemented in the first place.
Can you offer any insight?