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>
This commit is contained in:
Elbert Ronnie 2023-01-31 23:19:19 +00:00
parent a441939ba5
commit 615d3d2157
4 changed files with 15 additions and 22 deletions

View File

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

View File

@ -32,10 +32,7 @@ where
}
fn iter(&self) -> ArrayIter {
ArrayIter {
array: self,
index: 0,
}
ArrayIter::new(self)
}
fn drain(self: Box<Self>) -> Vec<Box<dyn Reflect>> {

View File

@ -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<T: Reflect, const N: usize> Array for [T; N] {
#[inline]
fn iter(&self) -> ArrayIter {
ArrayIter {
array: self,
index: 0,
}
ArrayIter::new(self)
}
#[inline]

View File

@ -176,10 +176,7 @@ impl Array for DynamicList {
}
fn iter(&self) -> ArrayIter {
ArrayIter {
array: self,
index: 0,
}
ArrayIter::new(self)
}
fn drain(self: Box<Self>) -> Vec<Box<dyn Reflect>> {