Skip to content

Commit 615d3d2

Browse files
committed
Add constructor new to ArrayIter (#7449)
# Objective - Fixes #7430. ## Solution - Changed fields of `ArrayIter` to be private. - Add a constructor `new` to `ArrayIter`. - Replace normal struct creation with `new`. --- ## Changelog - Add a constructor `new` to `ArrayIter`. Co-authored-by: Elbert Ronnie <103196773+elbertronnie@users.noreply.github.com>
1 parent a441939 commit 615d3d2

File tree

4 files changed

+15
-22
lines changed

4 files changed

+15
-22
lines changed

crates/bevy_reflect/src/array.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,7 @@ impl Array for DynamicArray {
270270

271271
#[inline]
272272
fn iter(&self) -> ArrayIter {
273-
ArrayIter {
274-
array: self,
275-
index: 0,
276-
}
273+
ArrayIter::new(self)
277274
}
278275

279276
#[inline]
@@ -303,8 +300,16 @@ impl Typed for DynamicArray {
303300

304301
/// An iterator over an [`Array`].
305302
pub struct ArrayIter<'a> {
306-
pub(crate) array: &'a dyn Array,
307-
pub(crate) index: usize,
303+
array: &'a dyn Array,
304+
index: usize,
305+
}
306+
307+
impl<'a> ArrayIter<'a> {
308+
/// Creates a new [`ArrayIter`].
309+
#[inline]
310+
pub const fn new(array: &'a dyn Array) -> ArrayIter {
311+
ArrayIter { array, index: 0 }
312+
}
308313
}
309314

310315
impl<'a> Iterator for ArrayIter<'a> {

crates/bevy_reflect/src/impls/smallvec.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ where
3232
}
3333

3434
fn iter(&self) -> ArrayIter {
35-
ArrayIter {
36-
array: self,
37-
index: 0,
38-
}
35+
ArrayIter::new(self)
3936
}
4037

4138
fn drain(self: Box<Self>) -> Vec<Box<dyn Reflect>> {

crates/bevy_reflect/src/impls/std.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,7 @@ macro_rules! impl_reflect_for_veclike {
198198

199199
#[inline]
200200
fn iter(&self) -> ArrayIter {
201-
ArrayIter {
202-
array: self,
203-
index: 0,
204-
}
201+
ArrayIter::new(self)
205202
}
206203

207204
#[inline]
@@ -552,10 +549,7 @@ impl<T: Reflect, const N: usize> Array for [T; N] {
552549

553550
#[inline]
554551
fn iter(&self) -> ArrayIter {
555-
ArrayIter {
556-
array: self,
557-
index: 0,
558-
}
552+
ArrayIter::new(self)
559553
}
560554

561555
#[inline]

crates/bevy_reflect/src/list.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,7 @@ impl Array for DynamicList {
176176
}
177177

178178
fn iter(&self) -> ArrayIter {
179-
ArrayIter {
180-
array: self,
181-
index: 0,
182-
}
179+
ArrayIter::new(self)
183180
}
184181

185182
fn drain(self: Box<Self>) -> Vec<Box<dyn Reflect>> {

0 commit comments

Comments
 (0)