summaryrefslogtreecommitdiff
path: root/ecs/src
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src')
-rw-r--r--ecs/src/query.rs23
1 files changed, 13 insertions, 10 deletions
diff --git a/ecs/src/query.rs b/ecs/src/query.rs
index 944deb1..d0fa872 100644
--- a/ecs/src/query.rs
+++ b/ecs/src/query.rs
@@ -40,9 +40,7 @@ where
{
/// Iterates over the entities matching this query.
#[must_use]
- pub fn iter<'this>(&'this self) -> ComponentIter<'world, Comps>
- where
- 'this: 'world,
+ pub fn iter(&'world self) -> ComponentIter<'world, Comps, QueryEntityIter<'world>>
{
#[cfg(feature = "debug")]
tracing::debug!("Searching for {}", std::any::type_name::<Comps>());
@@ -93,7 +91,7 @@ where
Comps: ComponentSequence,
OptionsT: Options,
{
- type IntoIter = ComponentIter<'world, Comps>;
+ type IntoIter = ComponentIter<'world, Comps, QueryEntityIter<'world>>;
type Item = Comps::Refs<'world>;
fn into_iter(self) -> Self::IntoIter
@@ -149,19 +147,24 @@ type ComponentIterMapFn = for<'a> fn(&'a Archetype) -> EntityIter<'a>;
type ComponentIterFilterFn = for<'a, 'b> fn(&'a &'b ArchetypeEntity) -> bool;
-pub struct ComponentIter<'world, Comps>
+type QueryEntityIter<'world> = Filter<
+ Flatten<Map<ArchetypeRefIter<'world>, ComponentIterMapFn>>,
+ ComponentIterFilterFn,
+>;
+
+pub struct ComponentIter<'world, Comps, EntityIter>
+where
+ EntityIter: Iterator<Item = &'world ArchetypeEntity>,
{
world: &'world World,
- entities: Filter<
- Flatten<Map<ArchetypeRefIter<'world>, ComponentIterMapFn>>,
- ComponentIterFilterFn,
- >,
+ entities: EntityIter,
comps_pd: PhantomData<Comps>,
}
-impl<'world, Comps> Iterator for ComponentIter<'world, Comps>
+impl<'world, Comps, EntityIter> Iterator for ComponentIter<'world, Comps, EntityIter>
where
Comps: ComponentSequence + 'world,
+ EntityIter: Iterator<Item = &'world ArchetypeEntity>,
{
type Item = Comps::Refs<'world>;