mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
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 <alice.i.cecile@gmail.com> Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
This commit is contained in:
parent
36a3e53e10
commit
64b987921c
1 changed files with 9 additions and 0 deletions
|
@ -406,6 +406,15 @@ impl TypeRegistry {
|
|||
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut TypeRegistration> {
|
||||
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<T: TypeData>(&self) -> impl Iterator<Item = (&TypeRegistration, &T)> {
|
||||
self.registrations.values().filter_map(|item| {
|
||||
let type_data = item.data::<T>();
|
||||
type_data.map(|data| (item, data))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeRegistryArc {
|
||||
|
|
Loading…
Reference in a new issue