From 7a7d3a350b22b5555c27debff6fee4fc6100fa38 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 18 Mar 2025 13:21:46 +0100 Subject: refactor(ecs): fix Clippy lints --- ecs/src/query/flexible.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'ecs/src/query/flexible.rs') diff --git a/ecs/src/query/flexible.rs b/ecs/src/query/flexible.rs index 3bb8fd6..c42ec25 100644 --- a/ecs/src/query/flexible.rs +++ b/ecs/src/query/flexible.rs @@ -1,5 +1,5 @@ //! Low-level querying. -use std::iter::{repeat_n, Filter, Flatten, Map, RepeatN, Zip}; +use std::iter::{repeat_n, Filter, FlatMap, RepeatN, Zip}; use crate::component::storage::archetype::{Archetype, ArchetypeEntity, EntityIter}; use crate::component::storage::{ArchetypeRefIter, Storage as ComponentStorage}; @@ -30,19 +30,18 @@ where { /// Iterates over the entities matching this query. #[must_use] - pub fn iter<'query, OptionsT: Options>(&'query self) -> Iter<'query> + pub fn iter(&self) -> Iter<'_> { Iter { iter: self .component_storage - .search_archetypes(&self.comp_metadata.as_ref()) - .map( + .search_archetypes(self.comp_metadata.as_ref()) + .flat_map( (|archetype| { repeat_n(archetype, archetype.entity_cnt()) .zip(archetype.entities()) }) as ComponentIterMapFn, ) - .flatten() .filter(|(_, entity)| OptionsT::entity_filter(&entity.components)), } } @@ -110,31 +109,39 @@ impl<'query> EntityHandle<'query> { /// Returns the [`Uid`] of this entity. #[inline] + #[must_use] pub fn uid(&self) -> Uid { self.entity.uid } #[inline] + #[must_use] pub fn components(&self) -> &'query [EntityComponent] { &self.entity.components } #[inline] + #[must_use] pub fn get_component_index(&self, component_uid: Uid) -> Option { self.archetype.get_index_for_component(component_uid) } } -type ComponentIterMapFn = - for<'a> fn(&'a Archetype) -> Zip, EntityIter<'a>>; +type ComponentIterMapFnOutput<'a> = Zip, EntityIter<'a>>; + +type ComponentIterMapFn = for<'a> fn(&'a Archetype) -> ComponentIterMapFnOutput<'a>; type ComponentIterFilterFn = for<'a, 'b> fn(&'a (&'b Archetype, &'b ArchetypeEntity)) -> bool; type QueryEntityIter<'query> = Filter< - Flatten, ComponentIterMapFn>>, + FlatMap< + ArchetypeRefIter<'query>, + ComponentIterMapFnOutput<'query>, + ComponentIterMapFn, + >, ComponentIterFilterFn, >; -- cgit v1.2.3-18-g5258