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 +++++++++++++++-------- ecs/src/query/options.rs | 10 +++++----- 2 files changed, 20 insertions(+), 13 deletions(-) (limited to 'ecs/src/query') 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, >; diff --git a/ecs/src/query/options.rs b/ecs/src/query/options.rs index 772d091..6318359 100644 --- a/ecs/src/query/options.rs +++ b/ecs/src/query/options.rs @@ -8,12 +8,12 @@ use crate::EntityComponent; /// Query options. pub trait Options { - fn entity_filter<'component>(components: &'component [EntityComponent]) -> bool; + fn entity_filter(components: &[EntityComponent]) -> bool; } impl Options for () { - fn entity_filter<'component>(_components: &'component [EntityComponent]) -> bool + fn entity_filter(_components: &[EntityComponent]) -> bool { true } @@ -30,10 +30,10 @@ impl Options for With where ComponentT: Component, { - fn entity_filter<'component>(components: &'component [EntityComponent]) -> bool + fn entity_filter(components: &[EntityComponent]) -> bool { let ids_set = components - .into_iter() + .iter() .map(|component| component.id) .collect::>(); @@ -52,7 +52,7 @@ impl Options for Not where OptionsT: Options, { - fn entity_filter<'component>(components: &'component [EntityComponent]) -> bool + fn entity_filter(components: &[EntityComponent]) -> bool { !OptionsT::entity_filter(components) } -- cgit v1.2.3-18-g5258