bevy/examples/games
Charles dfee7879c3 Add a clear() method to the EventReader that consumes the iterator (#4693)
# Objective

- It's pretty common to want to check if an EventReader has received one or multiple events while also needing to consume the iterator to "clear" the EventReader.
- The current approach is to do something like `events.iter().count() > 0` or `events.iter().last().is_some()`. It's not immediately obvious that the purpose of that is to consume the events and check if there were any events. My solution doesn't really solve that part, but it encapsulates the pattern.

## Solution

- Add a `.clear()` method that consumes the iterator.
	- It takes the EventReader by value to make sure it isn't used again after it has been called.

---

## Migration Guide

Not a breaking change, but if you ever found yourself in a situation where you needed to consume the EventReader and check if there was any events you can now use

```rust
fn system(events: EventReader<MyEvent>) {
	if !events.is_empty {
		events.clear();
		// Process the fact that one or more event was received
	}
}
```


Co-authored-by: Charles <IceSentry@users.noreply.github.com>
2022-05-13 00:57:04 +00:00
..
alien_cake_addict.rs Allow closing windows at runtime (#3575) 2022-05-05 13:35:43 +00:00
breakout.rs Add a clear() method to the EventReader that consumes the iterator (#4693) 2022-05-13 00:57:04 +00:00
contributors.rs More tidying of contributors example (#4443) 2022-04-14 19:30:36 +00:00
game_menu.rs Move Rect to bevy_ui and rename it to UiRect (#4276) 2022-04-25 19:20:38 +00:00