From edb5eb812bb6a3e7ed26526fab24b110be3828d4 Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 20 Jun 2024 22:04:31 +0200 Subject: refactor(ecs): move down ArchetypeRefIter struct & impls in module --- ecs/src/component/storage.rs | 62 ++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'ecs/src') diff --git a/ecs/src/component/storage.rs b/ecs/src/component/storage.rs index 42e0e4f..cff50cf 100644 --- a/ecs/src/component/storage.rs +++ b/ecs/src/component/storage.rs @@ -16,37 +16,6 @@ pub struct Storage pending_archetype_lookup_entries: Vec>, } -#[derive(Debug)] -pub struct ArchetypeRefIter<'component_storage> -{ - inner: SliceIter<'component_storage, usize>, - archetypes: &'component_storage [Archetype], -} - -impl<'component_storage> ArchetypeRefIter<'component_storage> -{ - fn new_empty() -> Self - { - Self { inner: [].iter(), archetypes: &[] } - } -} - -impl<'component_storage> Iterator for ArchetypeRefIter<'component_storage> -{ - type Item = &'component_storage Archetype; - - fn next(&mut self) -> Option - { - let archetype_index = *self.inner.next()?; - - Some( - self.archetypes - .get(archetype_index) - .expect("Archetype index in archetype lookup entry was not found"), - ) - } -} - impl Storage { pub fn find_entities( @@ -185,6 +154,37 @@ pub struct Archetype pub components: Vec>, } +#[derive(Debug)] +pub struct ArchetypeRefIter<'component_storage> +{ + inner: SliceIter<'component_storage, usize>, + archetypes: &'component_storage [Archetype], +} + +impl<'component_storage> ArchetypeRefIter<'component_storage> +{ + fn new_empty() -> Self + { + Self { inner: [].iter(), archetypes: &[] } + } +} + +impl<'component_storage> Iterator for ArchetypeRefIter<'component_storage> +{ + type Item = &'component_storage Archetype; + + fn next(&mut self) -> Option + { + let archetype_index = *self.inner.next()?; + + Some( + self.archetypes + .get(archetype_index) + .expect("Archetype index in archetype lookup entry was not found"), + ) + } +} + #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] struct ArchetypeComponentsHash { -- cgit v1.2.3-18-g5258