Borrow instead of consuming in EventReader::clear (#6851)
The PR fixes the interface of `EventReader::clear`. Currently, the method consumes the reader, which makes it unusable.
## Changelog
- `EventReader::clear` now takes a mutable reference instead of consuming the event reader.
## Migration Guide
`EventReader::clear` now takes a mutable reference instead of consuming the event reader. This means that `clear` now needs explicit mutable access to the reader variable, which previously could have been omitted in some cases:
```rust
// Old (0.9)
fn clear_events(reader: EventReader<SomeEvent>) {
reader.clear();
}
// New (0.10)
fn clear_events(mut reader: EventReader<SomeEvent>) {
reader.clear();
}
```
Co-authored-by: Carter Anderson <mcanders1@gmail.com>
This commit is contained in:
parent
77c59c22ab
commit
b337ed63ad
@ -226,7 +226,7 @@ impl<'w, 's, E: Event> EventReader<'w, 's, E> {
|
|||||||
/// #
|
/// #
|
||||||
/// struct CollisionEvent;
|
/// struct CollisionEvent;
|
||||||
///
|
///
|
||||||
/// fn play_collision_sound(events: EventReader<CollisionEvent>) {
|
/// fn play_collision_sound(mut events: EventReader<CollisionEvent>) {
|
||||||
/// if !events.is_empty() {
|
/// if !events.is_empty() {
|
||||||
/// events.clear();
|
/// events.clear();
|
||||||
/// // Play a sound
|
/// // Play a sound
|
||||||
@ -246,7 +246,7 @@ impl<'w, 's, E: Event> EventReader<'w, 's, E> {
|
|||||||
/// In those situations you generally want to consume those events to make sure they don't appear in the next frame.
|
/// In those situations you generally want to consume those events to make sure they don't appear in the next frame.
|
||||||
///
|
///
|
||||||
/// For more information see [`EventReader::is_empty()`].
|
/// For more information see [`EventReader::is_empty()`].
|
||||||
pub fn clear(mut self) {
|
pub fn clear(&mut self) {
|
||||||
self.iter().last();
|
self.iter().last();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -817,7 +817,7 @@ mod tests {
|
|||||||
events.send(TestEvent { i: 0 });
|
events.send(TestEvent { i: 0 });
|
||||||
world.insert_resource(events);
|
world.insert_resource(events);
|
||||||
|
|
||||||
let mut reader = IntoSystem::into_system(|events: EventReader<TestEvent>| -> bool {
|
let mut reader = IntoSystem::into_system(|mut events: EventReader<TestEvent>| -> bool {
|
||||||
if !events.is_empty() {
|
if !events.is_empty() {
|
||||||
events.clear();
|
events.clear();
|
||||||
false
|
false
|
||||||
|
|||||||
@ -404,7 +404,7 @@ fn check_for_collisions(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn play_collision_sound(
|
fn play_collision_sound(
|
||||||
collision_events: EventReader<CollisionEvent>,
|
mut collision_events: EventReader<CollisionEvent>,
|
||||||
audio: Res<Audio>,
|
audio: Res<Audio>,
|
||||||
sound: Res<CollisionSound>,
|
sound: Res<CollisionSound>,
|
||||||
) {
|
) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user