Skip to content

Commit

Permalink
Add EntityMap::iter() (#6935)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
Zeenobit committed Dec 16, 2022
1 parent 00fa0d8 commit f8e4b75
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/bevy_ecs/src/entity/map_entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,9 @@ impl EntityMap {
pub fn is_empty(&self) -> bool {
self.map.is_empty()
}

/// An iterator visiting all (key, value) pairs in arbitrary order.
pub fn iter(&self) -> impl Iterator<Item = (Entity, Entity)> + '_ {
self.map.iter().map(|(from, to)| (*from, *to))
}
}

0 comments on commit f8e4b75

Please sign in to comment.