diff --git a/crates/bevy_reflect/src/array.rs b/crates/bevy_reflect/src/array.rs index 438a135c040a3..005e6f6b7e497 100644 --- a/crates/bevy_reflect/src/array.rs +++ b/crates/bevy_reflect/src/array.rs @@ -270,10 +270,7 @@ impl Array for DynamicArray { #[inline] fn iter(&self) -> ArrayIter { - ArrayIter { - array: self, - index: 0, - } + ArrayIter::new(self) } #[inline] @@ -303,8 +300,16 @@ impl Typed for DynamicArray { /// An iterator over an [`Array`]. pub struct ArrayIter<'a> { - pub(crate) array: &'a dyn Array, - pub(crate) index: usize, + array: &'a dyn Array, + index: usize, +} + +impl<'a> ArrayIter<'a> { + /// Creates a new [`ArrayIter`]. + #[inline] + pub const fn new(array: &'a dyn Array) -> ArrayIter { + ArrayIter { array, index: 0 } + } } impl<'a> Iterator for ArrayIter<'a> { diff --git a/crates/bevy_reflect/src/impls/smallvec.rs b/crates/bevy_reflect/src/impls/smallvec.rs index 4a4c64e4ff9dd..c911653bd695c 100644 --- a/crates/bevy_reflect/src/impls/smallvec.rs +++ b/crates/bevy_reflect/src/impls/smallvec.rs @@ -32,10 +32,7 @@ where } fn iter(&self) -> ArrayIter { - ArrayIter { - array: self, - index: 0, - } + ArrayIter::new(self) } fn drain(self: Box) -> Vec> { diff --git a/crates/bevy_reflect/src/impls/std.rs b/crates/bevy_reflect/src/impls/std.rs index 9b7bbf8ff77fa..7e53a46a7ac53 100644 --- a/crates/bevy_reflect/src/impls/std.rs +++ b/crates/bevy_reflect/src/impls/std.rs @@ -198,10 +198,7 @@ macro_rules! impl_reflect_for_veclike { #[inline] fn iter(&self) -> ArrayIter { - ArrayIter { - array: self, - index: 0, - } + ArrayIter::new(self) } #[inline] @@ -552,10 +549,7 @@ impl Array for [T; N] { #[inline] fn iter(&self) -> ArrayIter { - ArrayIter { - array: self, - index: 0, - } + ArrayIter::new(self) } #[inline] diff --git a/crates/bevy_reflect/src/list.rs b/crates/bevy_reflect/src/list.rs index 2d67a62f24140..4940cb4828701 100644 --- a/crates/bevy_reflect/src/list.rs +++ b/crates/bevy_reflect/src/list.rs @@ -176,10 +176,7 @@ impl Array for DynamicList { } fn iter(&self) -> ArrayIter { - ArrayIter { - array: self, - index: 0, - } + ArrayIter::new(self) } fn drain(self: Box) -> Vec> {