diff --git a/crates/bevy_ecs/src/event.rs b/crates/bevy_ecs/src/event.rs index 95ef6ebbe4..9693bc18fa 100644 --- a/crates/bevy_ecs/src/event.rs +++ b/crates/bevy_ecs/src/event.rs @@ -390,12 +390,12 @@ impl<'w, 's, E: Event> EventReader<'w, 's, E> { /// Iterates over the events this [`EventReader`] has not seen yet. This updates the /// [`EventReader`]'s event counter, which means subsequent event reads will not include events /// that happened before now. - pub fn iter(&mut self) -> ManualEventIterator<'_, E> { + pub fn iter(&mut self) -> EventIterator<'_, E> { self.reader.iter(&self.events) } /// Like [`iter`](Self::iter), except also returning the [`EventId`] of the events. - pub fn iter_with_id(&mut self) -> ManualEventIteratorWithId<'_, E> { + pub fn iter_with_id(&mut self) -> EventIteratorWithId<'_, E> { self.reader.iter_with_id(&self.events) } @@ -442,7 +442,7 @@ impl<'w, 's, E: Event> EventReader<'w, 's, E> { impl<'a, 'w, 's, E: Event> IntoIterator for &'a mut EventReader<'w, 's, E> { type Item = &'a E; - type IntoIter = ManualEventIterator<'a, E>; + type IntoIter = EventIterator<'a, E>; fn into_iter(self) -> Self::IntoIter { self.iter() } @@ -541,16 +541,13 @@ impl Default for ManualEventReader { #[allow(clippy::len_without_is_empty)] // Check fails since the is_empty implementation has a signature other than `(&self) -> bool` impl ManualEventReader { /// See [`EventReader::iter`] - pub fn iter<'a>(&'a mut self, events: &'a Events) -> ManualEventIterator<'a, E> { + pub fn iter<'a>(&'a mut self, events: &'a Events) -> EventIterator<'a, E> { self.iter_with_id(events).without_id() } /// See [`EventReader::iter_with_id`] - pub fn iter_with_id<'a>( - &'a mut self, - events: &'a Events, - ) -> ManualEventIteratorWithId<'a, E> { - ManualEventIteratorWithId::new(self, events) + pub fn iter_with_id<'a>(&'a mut self, events: &'a Events) -> EventIteratorWithId<'a, E> { + EventIteratorWithId::new(self, events) } /// See [`EventReader::len`] @@ -585,11 +582,18 @@ impl ManualEventReader { /// An iterator that yields any unread events from an [`EventReader`] or [`ManualEventReader`]. #[derive(Debug)] -pub struct ManualEventIterator<'a, E: Event> { - iter: ManualEventIteratorWithId<'a, E>, +pub struct EventIterator<'a, E: Event> { + iter: EventIteratorWithId<'a, E>, } -impl<'a, E: Event> Iterator for ManualEventIterator<'a, E> { +/// An iterator that yields any unread events from an [`EventReader`] or [`ManualEventReader`]. +/// +/// This is a type alias for [`EventIterator`], which used to be called `ManualEventIterator`. +/// This type alias will be removed in the next release of bevy, so you should use [`EventIterator`] directly instead. +#[deprecated = "This type has been renamed to `EventIterator`."] +pub type ManualEventIterator<'a, E> = EventIterator<'a, E>; + +impl<'a, E: Event> Iterator for EventIterator<'a, E> { type Item = &'a E; fn next(&mut self) -> Option { self.iter.next().map(|(event, _)| event) @@ -615,7 +619,7 @@ impl<'a, E: Event> Iterator for ManualEventIterator<'a, E> { } } -impl<'a, E: Event> ExactSizeIterator for ManualEventIterator<'a, E> { +impl<'a, E: Event> ExactSizeIterator for EventIterator<'a, E> { fn len(&self) -> usize { self.iter.len() } @@ -623,13 +627,20 @@ impl<'a, E: Event> ExactSizeIterator for ManualEventIterator<'a, E> { /// An iterator that yields any unread events (and their IDs) from an [`EventReader`] or [`ManualEventReader`]. #[derive(Debug)] -pub struct ManualEventIteratorWithId<'a, E: Event> { +pub struct EventIteratorWithId<'a, E: Event> { reader: &'a mut ManualEventReader, chain: Chain>, Iter<'a, EventInstance>>, unread: usize, } -impl<'a, E: Event> ManualEventIteratorWithId<'a, E> { +/// An iterator that yields any unread events (and their IDs) from an [`EventReader`] or [`ManualEventReader`]. +/// +/// This is a type alias for [`EventIteratorWithId`], which used to be called `ManualEventIteratorWithId`. +/// This type alias will be removed in the next release of bevy, so you should use [`EventIteratorWithId`] directly instead. +#[deprecated = "This type has been renamed to `EventIteratorWithId`."] +pub type ManualEventIteratorWithId<'a, E> = EventIteratorWithId<'a, E>; + +impl<'a, E: Event> EventIteratorWithId<'a, E> { /// Creates a new iterator that yields any `events` that have not yet been seen by `reader`. pub fn new(reader: &'a mut ManualEventReader, events: &'a Events) -> Self { let a_index = (reader.last_event_count).saturating_sub(events.events_a.start_event_count); @@ -652,12 +663,12 @@ impl<'a, E: Event> ManualEventIteratorWithId<'a, E> { } /// Iterate over only the events. - pub fn without_id(self) -> ManualEventIterator<'a, E> { - ManualEventIterator { iter: self } + pub fn without_id(self) -> EventIterator<'a, E> { + EventIterator { iter: self } } } -impl<'a, E: Event> Iterator for ManualEventIteratorWithId<'a, E> { +impl<'a, E: Event> Iterator for EventIteratorWithId<'a, E> { type Item = (&'a E, EventId); fn next(&mut self) -> Option { match self @@ -706,7 +717,7 @@ impl<'a, E: Event> Iterator for ManualEventIteratorWithId<'a, E> { } } -impl<'a, E: Event> ExactSizeIterator for ManualEventIteratorWithId<'a, E> { +impl<'a, E: Event> ExactSizeIterator for EventIteratorWithId<'a, E> { fn len(&self) -> usize { self.unread } diff --git a/crates/bevy_ecs/src/removal_detection.rs b/crates/bevy_ecs/src/removal_detection.rs index 5546f17eac..cd58cfd019 100644 --- a/crates/bevy_ecs/src/removal_detection.rs +++ b/crates/bevy_ecs/src/removal_detection.rs @@ -4,9 +4,7 @@ use crate::{ self as bevy_ecs, component::{Component, ComponentId, ComponentIdFor, Tick}, entity::Entity, - event::{ - Event, EventId, Events, ManualEventIterator, ManualEventIteratorWithId, ManualEventReader, - }, + event::{Event, EventId, EventIterator, EventIteratorWithId, Events, ManualEventReader}, prelude::Local, storage::SparseSet, system::{ReadOnlySystemParam, SystemMeta, SystemParam}, @@ -145,7 +143,7 @@ pub struct RemovedComponents<'w, 's, T: Component> { /// /// See [`RemovedComponents`]. pub type RemovedIter<'a> = iter::Map< - iter::Flatten>>>, + iter::Flatten>>>, fn(RemovedComponentEntity) -> Entity, >; @@ -153,7 +151,7 @@ pub type RemovedIter<'a> = iter::Map< /// /// See [`RemovedComponents`]. pub type RemovedIterWithId<'a> = iter::Map< - iter::Flatten>>, + iter::Flatten>>, fn( (&RemovedComponentEntity, EventId), ) -> (Entity, EventId),