Basically, what I want to do is following. First I have a state. The state can generate a list of available events. This could look like this:
struct State;
impl State {
fn get_events(&mut self) -> impl Iterator<Item = Event> {...}
}
As long as iterating over the events, it should not be allowed to query the list of available events again.
That's why the state is mutably borrowed in method get_events
.
So next, it has to be ensured, that only one event is called. Therefore it's necessary to consume the iterator and to add a lifetime dependency for the iterator to the event types.