From f8e4b755ffde634a4f2c27f904a3a78a68d4eaa6 Mon Sep 17 00:00:00 2001 From: Zeenobit Date: Fri, 16 Dec 2022 20:14:13 +0000 Subject: [PATCH] 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. --- crates/bevy_ecs/src/entity/map_entities.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/bevy_ecs/src/entity/map_entities.rs b/crates/bevy_ecs/src/entity/map_entities.rs index 516588d1597c9..2a8dbfbc468c8 100644 --- a/crates/bevy_ecs/src/entity/map_entities.rs +++ b/crates/bevy_ecs/src/entity/map_entities.rs @@ -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 + '_ { + self.map.iter().map(|(from, to)| (*from, *to)) + } }