I've just rewritten part of my parser to use references instead of copying tokens... it took longer than I care to admit to figure it out.

I'm happy with the final results, but sometimes the borrow checker rears its head in ways I do not expect.

https://github.com/jacobmealey/slush/commit/29e01a76e52ba3d07c30bf6473316ebf10704b76

parser: Uses references to Vec<Token> instead of cloning tokens · jacobmealey/slush@29e01a7

A shell you can drink! Contribute to jacobmealey/slush development by creating an account on GitHub.

GitHub
I spent a while trying to hold a reference to &Token in my parser, but Rust doesn't like holding multiple references while also mutating state, which makes sense but I kept trying to force it to work.
The final solution I landed on is to use the index and index to the Token I want, which now feels very obvious.