1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use super::{Component, Vector};
use core::marker::PhantomData;
#[derive(Clone, Debug)]
pub struct Iter<'a, V, C>
where
V: Vector<C>,
C: Component,
{
vector: &'a V,
position: usize,
component: PhantomData<C>,
}
impl<'a, V, C> Iter<'a, V, C>
where
V: Vector<C>,
C: Component,
{
pub(super) fn new(vector: &'a V) -> Self {
Self {
vector,
position: 0,
component: PhantomData,
}
}
}
impl<'a, V, C> Iterator for Iter<'a, V, C>
where
V: Vector<C>,
C: Component,
{
type Item = C;
fn next(&mut self) -> Option<C> {
let item = self.vector.get(self.position);
if item.is_some() {
self.position += 1;
}
item
}
}