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:
Mateusz Wachowiak 2024-04-26 04:09:34 +02:00 committed by GitHub
parent 36a3e53e10
commit 64b987921c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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 {