Skip to content

Commit b2090e3

Browse files
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<Item = (ComponentId, &ResourceData)>`
1 parent 69011b7 commit b2090e3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

crates/bevy_ecs/src/storage/resource.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ impl Resources {
137137
self.resources.len()
138138
}
139139

140+
/// Iterate over all resources that have been initialized, i.e. given a [`ComponentId`]
141+
pub fn iter(&self) -> impl Iterator<Item = (ComponentId, &ResourceData)> {
142+
self.resources.iter().map(|(id, data)| (*id, data))
143+
}
144+
140145
/// Returns true if there are no resources stored in the [`World`],
141146
/// false otherwise.
142147
///

0 commit comments

Comments
 (0)