From 4c8b85c18806da23ca6439a41a3a6aa9288ad7b3 Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Mon, 14 Nov 2022 23:08:27 +0000 Subject: [PATCH] add `Resources::iter` to iterate over all resource IDs (#6592) # Objective In bevy 0.8 you could list all resources using `world.archetypes().resource().components()`. As far as I can tell the resource archetype has been replaced with the `Resources` storage, and it would be nice if it could be used to iterate over all resource component IDs as well. ## Solution - add `fn Resources::iter(&self) -> impl Iterator` --- crates/bevy_ecs/src/storage/resource.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/bevy_ecs/src/storage/resource.rs b/crates/bevy_ecs/src/storage/resource.rs index edfa51e12857a..e047fb3c96bf8 100644 --- a/crates/bevy_ecs/src/storage/resource.rs +++ b/crates/bevy_ecs/src/storage/resource.rs @@ -137,6 +137,11 @@ impl Resources { self.resources.len() } + /// Iterate over all resources that have been initialized, i.e. given a [`ComponentId`] + pub fn iter(&self) -> impl Iterator { + self.resources.iter().map(|(id, data)| (*id, data)) + } + /// Returns true if there are no resources stored in the [`World`], /// false otherwise. ///