Skip to content

Commit

Permalink
add Resources::iter to iterate over all resource IDs (#6592)
Browse files Browse the repository at this point in the history
# 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)>`
  • Loading branch information
jakobhellermann committed Nov 14, 2022
1 parent 69011b7 commit b2090e3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/bevy_ecs/src/storage/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = (ComponentId, &ResourceData)> {
self.resources.iter().map(|(id, data)| (*id, data))
}

/// Returns true if there are no resources stored in the [`World`],
/// false otherwise.
///
Expand Down

0 comments on commit b2090e3

Please sign in to comment.