Need an example of using itertools::PutBack::put_back in a loop


I am trying to use itertools::PutBack::put_back in a loop. It is the event loop of a lexical analyzer state machine. I keep running afoul of the borrow checker. Does anyone have an example of how to use put_back properly?

In particular, I will be iterating over the characters in a string.


I saw your question over on stack overflow so I answered it there.


Thank you! I will read your answer…
… Read it. Very helpful.