Skip to content

Instantly share code, notes, and snippets.

@porky11
Created January 4, 2019 23:41
Show Gist options
  • Save porky11/b2508fc965a3ddd8d987d1e84616c0b5 to your computer and use it in GitHub Desktop.
Save porky11/b2508fc965a3ddd8d987d1e84616c0b5 to your computer and use it in GitHub Desktop.
Event system

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment