iterate_with_return

Function iterate_with_return 

Source
pub fn iterate_with_return<G, F>(
    generator: G,
    handle_return: F,
) -> impl Iterator<Item = G::Yield>
where G: Generator, F: FnOnce(G::Return) -> Option<G::Yield>,
Expand description

Turns the given generator into an iterator, with a function to handle the GeneratorState::Complete(_) case.

The returned iterator iterates over Generator::Yield. When GeneratorState::Complete(_) is returned, it calls handle_return with the returned value. The return of that call is then emitted from the iterator. All subsequent calls to Iterator::next then return None.