From 91cc714fa961b8cef0c71094aa5afad7fa3990e9 Mon Sep 17 00:00:00 2001 From: Aceeri Date: Sun, 25 Dec 2022 03:20:55 -0800 Subject: [PATCH] Remove unnecessary type for iterator --- crates/bevy_ecs/src/removal_detection.rs | 30 +++++++----------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/crates/bevy_ecs/src/removal_detection.rs b/crates/bevy_ecs/src/removal_detection.rs index 127e6df1f0c07c..5d92c5ee7a8f02 100644 --- a/crates/bevy_ecs/src/removal_detection.rs +++ b/crates/bevy_ecs/src/removal_detection.rs @@ -12,7 +12,7 @@ use bevy_ecs_macros::SystemParam; use std::{ fmt::Debug, - iter::Cloned, + iter::{Cloned, Flatten}, marker::PhantomData, ops::{Deref, DerefMut}, }; @@ -117,27 +117,15 @@ pub struct RemovedComponents<'w, 's, T: Component> { event_sets: &'w RemovedComponentEvents, } -pub enum MaybeIter { - Iter(I), - Empty, -} +type RemovedIter<'a> = Flatten>>>; -impl Iterator for MaybeIter { - type Item = I::Item; - fn next(&mut self) -> Option { - match self { - MaybeIter::Iter(iter) => iter.next(), - MaybeIter::Empty => None, - } - } -} impl<'w, 's, T: Component> RemovedComponents<'w, 's, T> { - pub fn iter(&mut self) -> MaybeIter>> { - if let Some(events) = self.event_sets.get(**self.component_id) { - MaybeIter::Iter(self.reader.iter(events).cloned()) - } else { - MaybeIter::Empty - } + pub fn iter(&mut self) -> RemovedIter<'_> { + self.event_sets + .get(**self.component_id) + .map(|events| self.reader.iter(events).cloned()) + .into_iter() + .flatten() } } @@ -146,7 +134,7 @@ where T: Component, { type Item = Entity; - type IntoIter = MaybeIter>>; + type IntoIter = RemovedIter<'a>; fn into_iter(self) -> Self::IntoIter { self.iter() }