bevy_reflect: Allow construction of MapIter outside of the bevy_reflect crate. (#8723)

# Objective

Right now it's impossible to construct a MapIter outside of the
bevy_reflect crate, making it impossible to implement the Map trait for
custom map types.

## Solution

Addition of a pub constructor to MapIter.
This commit is contained in:
Gauthier Acquitter 2023-06-01 12:12:57 +02:00 committed by GitHub
parent bea7fd1c0b
commit acf1362b9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 10 deletions

View file

@ -379,10 +379,7 @@ macro_rules! impl_reflect_for_hashmap {
}
fn iter(&self) -> MapIter {
MapIter {
map: self,
index: 0,
}
MapIter::new(self)
}
fn drain(self: Box<Self>) -> Vec<(Box<dyn Reflect>, Box<dyn Reflect>)> {

View file

@ -245,10 +245,7 @@ impl Map for DynamicMap {
}
fn iter(&self) -> MapIter {
MapIter {
map: self,
index: 0,
}
MapIter::new(self)
}
fn get_at(&self, index: usize) -> Option<(&dyn Reflect, &dyn Reflect)> {
@ -377,8 +374,16 @@ impl Debug for DynamicMap {
/// An iterator over the key-value pairs of a [`Map`].
pub struct MapIter<'a> {
pub(crate) map: &'a dyn Map,
pub(crate) index: usize,
map: &'a dyn Map,
index: usize,
}
impl<'a> MapIter<'a> {
/// Creates a new [`MapIter`].
#[inline]
pub const fn new(map: &'a dyn Map) -> MapIter {
MapIter { map, index: 0 }
}
}
impl<'a> Iterator for MapIter<'a> {