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:
		
							parent
							
								
									a441939ba5
								
							
						
					
					
						commit
						615d3d2157
					
				| @ -270,10 +270,7 @@ impl Array for DynamicArray { | |||||||
| 
 | 
 | ||||||
|     #[inline] |     #[inline] | ||||||
|     fn iter(&self) -> ArrayIter { |     fn iter(&self) -> ArrayIter { | ||||||
|         ArrayIter { |         ArrayIter::new(self) | ||||||
|             array: self, |  | ||||||
|             index: 0, |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #[inline] |     #[inline] | ||||||
| @ -303,8 +300,16 @@ impl Typed for DynamicArray { | |||||||
| 
 | 
 | ||||||
| /// An iterator over an [`Array`].
 | /// An iterator over an [`Array`].
 | ||||||
| pub struct ArrayIter<'a> { | pub struct ArrayIter<'a> { | ||||||
|     pub(crate) array: &'a dyn Array, |     array: &'a dyn Array, | ||||||
|     pub(crate) index: usize, |     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> { | impl<'a> Iterator for ArrayIter<'a> { | ||||||
|  | |||||||
| @ -32,10 +32,7 @@ where | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn iter(&self) -> ArrayIter { |     fn iter(&self) -> ArrayIter { | ||||||
|         ArrayIter { |         ArrayIter::new(self) | ||||||
|             array: self, |  | ||||||
|             index: 0, |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn drain(self: Box<Self>) -> Vec<Box<dyn Reflect>> { |     fn drain(self: Box<Self>) -> Vec<Box<dyn Reflect>> { | ||||||
|  | |||||||
| @ -198,10 +198,7 @@ macro_rules! impl_reflect_for_veclike { | |||||||
| 
 | 
 | ||||||
|             #[inline] |             #[inline] | ||||||
|             fn iter(&self) -> ArrayIter { |             fn iter(&self) -> ArrayIter { | ||||||
|                 ArrayIter { |                 ArrayIter::new(self) | ||||||
|                     array: self, |  | ||||||
|                     index: 0, |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             #[inline] |             #[inline] | ||||||
| @ -552,10 +549,7 @@ impl<T: Reflect, const N: usize> Array for [T; N] { | |||||||
| 
 | 
 | ||||||
|     #[inline] |     #[inline] | ||||||
|     fn iter(&self) -> ArrayIter { |     fn iter(&self) -> ArrayIter { | ||||||
|         ArrayIter { |         ArrayIter::new(self) | ||||||
|             array: self, |  | ||||||
|             index: 0, |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #[inline] |     #[inline] | ||||||
|  | |||||||
| @ -176,10 +176,7 @@ impl Array for DynamicList { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn iter(&self) -> ArrayIter { |     fn iter(&self) -> ArrayIter { | ||||||
|         ArrayIter { |         ArrayIter::new(self) | ||||||
|             array: self, |  | ||||||
|             index: 0, |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn drain(self: Box<Self>) -> Vec<Box<dyn Reflect>> { |     fn drain(self: Box<Self>) -> Vec<Box<dyn Reflect>> { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Elbert Ronnie
						Elbert Ronnie