Skip to content

Commit

Permalink
exact sized event iterators (bevyengine#3863)
Browse files Browse the repository at this point in the history
# Objective

- Remove `Resource` binding on events, introduce a new `Event` trait
- Ensure event iterators are `ExactSizeIterator`

## Solution

- Builds on bevyengine#2382 and bevyengine#2969

## Changelog

- Events<T>, EventWriter<T>, EventReader<T> and so on now require that the underlying type is Event, rather than Resource. Both of these are trivial supertraits of Send + Sync + 'static with universal blanket implementations: this change is currently purely cosmetic.
- Event reader iterators now implement ExactSizeIterator
  • Loading branch information
mockersf authored and ItsDoot committed Feb 1, 2023
1 parent 0fd621a commit 2257821
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 83 deletions.
4 changes: 2 additions & 2 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{CoreStage, Plugin, PluginGroup, PluginGroupBuilder, StartupSchedule, StartupStage};
pub use bevy_derive::AppLabel;
use bevy_ecs::{
event::Events,
event::{Event, Events},
prelude::{FromWorld, IntoExclusiveSystem},
schedule::{
IntoSystemDescriptor, Schedule, ShouldRun, Stage, StageLabel, State, StateData, SystemSet,
Expand Down Expand Up @@ -622,7 +622,7 @@ impl App {
/// ```
pub fn add_event<T>(&mut self) -> &mut Self
where
T: Resource,
T: Event,
{
if !self.world.contains_resource::<Events<T>>() {
self.init_resource::<Events<T>>()
Expand Down
Loading

0 comments on commit 2257821

Please sign in to comment.