Skip to content

Commit f8e4b75

Browse files
committed
Add EntityMap::iter() (#6935)
# Objective There is currently no way to iterate over key/value pairs inside an `EntityMap`, which makes the usage of this struct very awkward. I couldn't think of a good reason why the `iter()` function should not be exposed, considering the interface already exposes `keys()` and `values()`, so I made this PR. ## Solution Implement `iter()` for `EntityMap` in terms of its inner map type.
1 parent 00fa0d8 commit f8e4b75

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

crates/bevy_ecs/src/entity/map_entities.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,9 @@ impl EntityMap {
117117
pub fn is_empty(&self) -> bool {
118118
self.map.is_empty()
119119
}
120+
121+
/// An iterator visiting all (key, value) pairs in arbitrary order.
122+
pub fn iter(&self) -> impl Iterator<Item = (Entity, Entity)> + '_ {
123+
self.map.iter().map(|(from, to)| (*from, *to))
124+
}
120125
}

0 commit comments

Comments
 (0)