Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions crates/bevy_reflect/src/impls/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>)> {
Expand Down
17 changes: 11 additions & 6 deletions crates/bevy_reflect/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)> {
Expand Down Expand Up @@ -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> {
Expand Down