Override size_hint for all Iterators and add ExactSizeIterator where applicable (#1734)
After #1697 I looked at all other Iterators from Bevy and added overrides for `size_hint` where it wasn't done. Also implemented `ExactSizeIterator` where applicable.
This commit is contained in:
parent
b060e16f62
commit
0fce6f0406
@ -149,8 +149,15 @@ impl<'a> Iterator for ListIter<'a> {
|
||||
self.index += 1;
|
||||
value
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
let size = self.list.len();
|
||||
(size, Some(size))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ExactSizeIterator for ListIter<'a> {}
|
||||
|
||||
#[inline]
|
||||
pub fn list_apply<L: List>(a: &mut L, b: &dyn Reflect) {
|
||||
if let ReflectRef::List(list_value) = b.reflect_ref() {
|
||||
|
||||
@ -167,8 +167,15 @@ impl<'a> Iterator for MapIter<'a> {
|
||||
self.index += 1;
|
||||
value
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
let size = self.map.len();
|
||||
(size, Some(size))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ExactSizeIterator for MapIter<'a> {}
|
||||
|
||||
#[inline]
|
||||
pub fn map_partial_eq<M: Map>(a: &M, b: &dyn Reflect) -> Option<bool> {
|
||||
let map = if let ReflectRef::Map(map) = b.reflect_ref() {
|
||||
|
||||
@ -37,8 +37,15 @@ impl<'a> Iterator for FieldIter<'a> {
|
||||
self.index += 1;
|
||||
value
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
let size = self.struct_val.field_len();
|
||||
(size, Some(size))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ExactSizeIterator for FieldIter<'a> {}
|
||||
|
||||
pub trait GetField {
|
||||
fn get_field<T: Reflect>(&self, name: &str) -> Option<&T>;
|
||||
fn get_field_mut<T: Reflect>(&mut self, name: &str) -> Option<&mut T>;
|
||||
|
||||
@ -32,8 +32,15 @@ impl<'a> Iterator for TupleFieldIter<'a> {
|
||||
self.index += 1;
|
||||
value
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
let size = self.tuple.field_len();
|
||||
(size, Some(size))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ExactSizeIterator for TupleFieldIter<'a> {}
|
||||
|
||||
pub trait GetTupleField {
|
||||
fn get_field<T: Reflect>(&self, index: usize) -> Option<&T>;
|
||||
fn get_field_mut<T: Reflect>(&mut self, index: usize) -> Option<&mut T>;
|
||||
|
||||
@ -32,8 +32,15 @@ impl<'a> Iterator for TupleStructFieldIter<'a> {
|
||||
self.index += 1;
|
||||
value
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
let size = self.tuple_struct.field_len();
|
||||
(size, Some(size))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ExactSizeIterator for TupleStructFieldIter<'a> {}
|
||||
|
||||
pub trait GetTupleStructField {
|
||||
fn get_field<T: Reflect>(&self, index: usize) -> Option<&T>;
|
||||
fn get_field_mut<T: Reflect>(&mut self, index: usize) -> Option<&mut T>;
|
||||
|
||||
@ -118,8 +118,15 @@ impl<'a> Iterator for RenderResourceIterator<'a> {
|
||||
Some(render_resource)
|
||||
}
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
let size = self.render_resources.render_resources_len();
|
||||
(size, Some(size))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ExactSizeIterator for RenderResourceIterator<'a> {}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! impl_render_resource_bytes {
|
||||
($ty:ident) => {
|
||||
|
||||
@ -228,8 +228,17 @@ impl<'a> Iterator for ShaderStagesIterator<'a> {
|
||||
self.state += 1;
|
||||
ret
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
if self.shader_stages.fragment.is_some() {
|
||||
return (2, Some(2));
|
||||
}
|
||||
(1, Some(1))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ExactSizeIterator for ShaderStagesIterator<'a> {}
|
||||
|
||||
impl ShaderStages {
|
||||
pub fn new(vertex_shader: Handle<Shader>) -> Self {
|
||||
ShaderStages {
|
||||
|
||||
@ -49,6 +49,10 @@ impl<'a> Iterator for ShaderDefIterator<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
(0, Some(self.shader_defs.shader_defs_len()))
|
||||
}
|
||||
}
|
||||
|
||||
impl ShaderDef for bool {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user