Rename ManualEventIterator (#9592)
# Objective
The name `ManualEventIterator` is long and unnecessary, as this is the
iterator type used for both `EventReader` and `ManualEventReader`.
## Solution
Rename `ManualEventIterator` to `EventIterator`. To ease migration, add
a deprecated type alias with the old name.
---
## Changelog
- The types `ManualEventIterator{WithId}` have been renamed to
`EventIterator{WithId}`.
## Migration Guide
The type `ManualEventIterator` has been renamed to `EventIterator`.
Additonally, `ManualEventIteratorWithId` has been renamed to
`EventIteratorWithId`.
This commit is contained in:
parent
da8ab16d83
commit
a47a5b30fe
@ -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
|
/// 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
|
/// [`EventReader`]'s event counter, which means subsequent event reads will not include events
|
||||||
/// that happened before now.
|
/// that happened before now.
|
||||||
pub fn iter(&mut self) -> ManualEventIterator<'_, E> {
|
pub fn iter(&mut self) -> EventIterator<'_, E> {
|
||||||
self.reader.iter(&self.events)
|
self.reader.iter(&self.events)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Like [`iter`](Self::iter), except also returning the [`EventId`] of the 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)
|
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> {
|
impl<'a, 'w, 's, E: Event> IntoIterator for &'a mut EventReader<'w, 's, E> {
|
||||||
type Item = &'a E;
|
type Item = &'a E;
|
||||||
type IntoIter = ManualEventIterator<'a, E>;
|
type IntoIter = EventIterator<'a, E>;
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
self.iter()
|
self.iter()
|
||||||
}
|
}
|
||||||
@ -541,16 +541,13 @@ impl<E: Event> Default for ManualEventReader<E> {
|
|||||||
#[allow(clippy::len_without_is_empty)] // Check fails since the is_empty implementation has a signature other than `(&self) -> bool`
|
#[allow(clippy::len_without_is_empty)] // Check fails since the is_empty implementation has a signature other than `(&self) -> bool`
|
||||||
impl<E: Event> ManualEventReader<E> {
|
impl<E: Event> ManualEventReader<E> {
|
||||||
/// See [`EventReader::iter`]
|
/// See [`EventReader::iter`]
|
||||||
pub fn iter<'a>(&'a mut self, events: &'a Events<E>) -> ManualEventIterator<'a, E> {
|
pub fn iter<'a>(&'a mut self, events: &'a Events<E>) -> EventIterator<'a, E> {
|
||||||
self.iter_with_id(events).without_id()
|
self.iter_with_id(events).without_id()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// See [`EventReader::iter_with_id`]
|
/// See [`EventReader::iter_with_id`]
|
||||||
pub fn iter_with_id<'a>(
|
pub fn iter_with_id<'a>(&'a mut self, events: &'a Events<E>) -> EventIteratorWithId<'a, E> {
|
||||||
&'a mut self,
|
EventIteratorWithId::new(self, events)
|
||||||
events: &'a Events<E>,
|
|
||||||
) -> ManualEventIteratorWithId<'a, E> {
|
|
||||||
ManualEventIteratorWithId::new(self, events)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// See [`EventReader::len`]
|
/// See [`EventReader::len`]
|
||||||
@ -585,11 +582,18 @@ impl<E: Event> ManualEventReader<E> {
|
|||||||
|
|
||||||
/// An iterator that yields any unread events from an [`EventReader`] or [`ManualEventReader`].
|
/// An iterator that yields any unread events from an [`EventReader`] or [`ManualEventReader`].
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ManualEventIterator<'a, E: Event> {
|
pub struct EventIterator<'a, E: Event> {
|
||||||
iter: ManualEventIteratorWithId<'a, E>,
|
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;
|
type Item = &'a E;
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
self.iter.next().map(|(event, _)| event)
|
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 {
|
fn len(&self) -> usize {
|
||||||
self.iter.len()
|
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`].
|
/// An iterator that yields any unread events (and their IDs) from an [`EventReader`] or [`ManualEventReader`].
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ManualEventIteratorWithId<'a, E: Event> {
|
pub struct EventIteratorWithId<'a, E: Event> {
|
||||||
reader: &'a mut ManualEventReader<E>,
|
reader: &'a mut ManualEventReader<E>,
|
||||||
chain: Chain<Iter<'a, EventInstance<E>>, Iter<'a, EventInstance<E>>>,
|
chain: Chain<Iter<'a, EventInstance<E>>, Iter<'a, EventInstance<E>>>,
|
||||||
unread: usize,
|
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`.
|
/// Creates a new iterator that yields any `events` that have not yet been seen by `reader`.
|
||||||
pub fn new(reader: &'a mut ManualEventReader<E>, events: &'a Events<E>) -> Self {
|
pub fn new(reader: &'a mut ManualEventReader<E>, events: &'a Events<E>) -> Self {
|
||||||
let a_index = (reader.last_event_count).saturating_sub(events.events_a.start_event_count);
|
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.
|
/// Iterate over only the events.
|
||||||
pub fn without_id(self) -> ManualEventIterator<'a, E> {
|
pub fn without_id(self) -> EventIterator<'a, E> {
|
||||||
ManualEventIterator { iter: self }
|
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<E>);
|
type Item = (&'a E, EventId<E>);
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
match self
|
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 {
|
fn len(&self) -> usize {
|
||||||
self.unread
|
self.unread
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,9 +4,7 @@ use crate::{
|
|||||||
self as bevy_ecs,
|
self as bevy_ecs,
|
||||||
component::{Component, ComponentId, ComponentIdFor, Tick},
|
component::{Component, ComponentId, ComponentIdFor, Tick},
|
||||||
entity::Entity,
|
entity::Entity,
|
||||||
event::{
|
event::{Event, EventId, EventIterator, EventIteratorWithId, Events, ManualEventReader},
|
||||||
Event, EventId, Events, ManualEventIterator, ManualEventIteratorWithId, ManualEventReader,
|
|
||||||
},
|
|
||||||
prelude::Local,
|
prelude::Local,
|
||||||
storage::SparseSet,
|
storage::SparseSet,
|
||||||
system::{ReadOnlySystemParam, SystemMeta, SystemParam},
|
system::{ReadOnlySystemParam, SystemMeta, SystemParam},
|
||||||
@ -145,7 +143,7 @@ pub struct RemovedComponents<'w, 's, T: Component> {
|
|||||||
///
|
///
|
||||||
/// See [`RemovedComponents`].
|
/// See [`RemovedComponents`].
|
||||||
pub type RemovedIter<'a> = iter::Map<
|
pub type RemovedIter<'a> = iter::Map<
|
||||||
iter::Flatten<option::IntoIter<iter::Cloned<ManualEventIterator<'a, RemovedComponentEntity>>>>,
|
iter::Flatten<option::IntoIter<iter::Cloned<EventIterator<'a, RemovedComponentEntity>>>>,
|
||||||
fn(RemovedComponentEntity) -> Entity,
|
fn(RemovedComponentEntity) -> Entity,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
@ -153,7 +151,7 @@ pub type RemovedIter<'a> = iter::Map<
|
|||||||
///
|
///
|
||||||
/// See [`RemovedComponents`].
|
/// See [`RemovedComponents`].
|
||||||
pub type RemovedIterWithId<'a> = iter::Map<
|
pub type RemovedIterWithId<'a> = iter::Map<
|
||||||
iter::Flatten<option::IntoIter<ManualEventIteratorWithId<'a, RemovedComponentEntity>>>,
|
iter::Flatten<option::IntoIter<EventIteratorWithId<'a, RemovedComponentEntity>>>,
|
||||||
fn(
|
fn(
|
||||||
(&RemovedComponentEntity, EventId<RemovedComponentEntity>),
|
(&RemovedComponentEntity, EventId<RemovedComponentEntity>),
|
||||||
) -> (Entity, EventId<RemovedComponentEntity>),
|
) -> (Entity, EventId<RemovedComponentEntity>),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user