1use super::*;
2use std::marker::PhantomData;
3impl<T> AutoVec<T> {
4 pub fn iter_mut(&self) -> IterMut<T> {
5 IterMut {
6 last: &self.children[self.len() - 1] as *const _,
7 current: unsafe {(&self.children[0] as *const *const RawAutoChild<T>).sub(1)},
8 lifetime: PhantomData,
9 }
10 }
11 pub fn iter(&self) -> Iter<T> {
12 Iter {
13 last: &self.children[self.len() - 1] as *const _,
14 current: unsafe {(&self.children[0] as *const *const RawAutoChild<T>).sub(1)},
15 lifetime: PhantomData,
16 }
17 }
18}
19pub struct Iter<'a, T> {
20 last: *const *const RawAutoChild<T>,
21 current: *const *const RawAutoChild<T>,
22 lifetime: PhantomData<&'a T>
23}
24pub struct IterMut<'a, T> {
25 last: *const *const RawAutoChild<T>,
26 current: *const *const RawAutoChild<T>,
27 lifetime: PhantomData<&'a T>
28}
29impl<'a, T> Iterator for Iter<'a, T> {
30 type Item = &'a T;
31 #[inline]
32 fn next(&mut self) -> Option<Self::Item> {
33 unsafe {self.current = self.current.add(1)};
34 if self.current > self.last {
35 None
36 } else {
37 unsafe {Some(&((&**self.current).child))}
38 }
39 }
40}
41impl<'a, T> Iterator for IterMut<'a, T> {
42 type Item = &'a mut T;
43 #[inline]
44 fn next(&mut self) -> Option<Self::Item> {
45 unsafe {self.current = self.current.add(1)};
46 if self.current > self.last {
47 None
48 } else {
49 unsafe {Some(&mut (&mut *(*self.current as *mut RawAutoChild<T>)).child)}
50 }
51 }
52}
53impl<'a, T> IntoIterator for &'a AutoVec<T> {
54 type Item = &'a T;
55 type IntoIter = Iter<'a, T>;
56 fn into_iter(self) -> Self::IntoIter {
57 self.iter()
58 }
59}
60impl<'a, T> IntoIterator for &'a mut AutoVec<T> {
61 type Item = &'a mut T;
62 type IntoIter = IterMut<'a, T>;
63 fn into_iter(self) -> Self::IntoIter {
64 self.iter_mut()
65 }
66}