I would like to declare a lifetime for a closure in Rust, but I can\'t find a way to add a lifetime declaration.
use std::str::SplitWhitespace;
pub struct P
I don't know how to answer your question, but there are two ways to solve the problem:
The easiest one is to let the closure reference the iterator directly.
{
let mut nt = || tokens.next().ok_or(missing_token(line_number));
// call the closure as many times as you need to
}
// At this point `tokens` will be usable again.
If you don't actually need do anything else with tokens
afterwards, just do:
let mut nt = || tokens.next().ok_or(missing_token(line_number));
The other solution is to write a function that emulates what the closure is doing and call that instead.