From 64b987921c4a4d54c3f250ae63bb9eb6b44a02aa Mon Sep 17 00:00:00 2001 From: Mateusz Wachowiak Date: Fri, 26 Apr 2024 04:09:34 +0200 Subject: [PATCH] iter_with_data (#13102) # Objective - Provide a way to iterate over the registered TypeData. ## Solution - a new method on the `TypeRegistry` that iterates over `TypeRegistrations` with theirs `TypeData` --------- Co-authored-by: Alice Cecile Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com> --- crates/bevy_reflect/src/type_registry.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/bevy_reflect/src/type_registry.rs b/crates/bevy_reflect/src/type_registry.rs index 2090094fea..6940a14542 100644 --- a/crates/bevy_reflect/src/type_registry.rs +++ b/crates/bevy_reflect/src/type_registry.rs @@ -406,6 +406,15 @@ impl TypeRegistry { pub fn iter_mut(&mut self) -> impl Iterator { self.registrations.values_mut() } + + /// Checks to see if the [`TypeData`] of type `T` is associated with each registered type, + /// returning a ([`TypeRegistration`], [`TypeData`]) iterator for all entries where data of that type was found. + pub fn iter_with_data(&self) -> impl Iterator { + self.registrations.values().filter_map(|item| { + let type_data = item.data::(); + type_data.map(|data| (item, data)) + }) + } } impl TypeRegistryArc {