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

[Merged by Bors] - Add constructor new to ArrayIter #7449

Closed
Closed
Show file tree
Hide file tree
Changes from 2 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
19 changes: 13 additions & 6 deletions crates/bevy_reflect/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,7 @@ impl Array for DynamicArray {

#[inline]
fn iter(&self) -> ArrayIter {
ArrayIter {
array: self,
index: 0,
}
ArrayIter::new(self)
}

#[inline]
Expand Down Expand Up @@ -303,8 +300,18 @@ 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`].
///
/// It is an [`Iterator`] for [`Array`] whose elements start from `index`.
elbertronnie marked this conversation as resolved.
Show resolved Hide resolved
#[inline]
pub const fn new(array: &'a dyn Array) -> ArrayIter {
ArrayIter { array, index: 0 }
}
}

impl<'a> Iterator for ArrayIter<'a> {
Expand Down
5 changes: 1 addition & 4 deletions crates/bevy_reflect/src/impls/smallvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>> {
Expand Down
10 changes: 2 additions & 8 deletions crates/bevy_reflect/src/impls/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,7 @@ macro_rules! impl_reflect_for_veclike {

#[inline]
fn iter(&self) -> ArrayIter {
ArrayIter {
array: self,
index: 0,
}
ArrayIter::new(self)
}

#[inline]
Expand Down Expand Up @@ -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]
Expand Down
5 changes: 1 addition & 4 deletions crates/bevy_reflect/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>> {
Expand Down