1use core::iter::FusedIterator;
23use crate::InlineArray;
45/// A consuming iterator over the elements of an `InlineArray`.
6pub struct Iter<A, T> {
7pub(crate) array: InlineArray<A, T>,
8}
910impl<A, T> Iterator for Iter<A, T> {
11type Item = A;
1213fn next(&mut self) -> Option<Self::Item> {
14self.array.remove(0)
15 }
1617fn size_hint(&self) -> (usize, Option<usize>) {
18 (self.array.len(), Some(self.array.len()))
19 }
20}
2122impl<A, T> DoubleEndedIterator for Iter<A, T> {
23fn next_back(&mut self) -> Option<Self::Item> {
24self.array.pop()
25 }
26}
2728impl<A, T> ExactSizeIterator for Iter<A, T> {}
2930impl<A, T> FusedIterator for Iter<A, T> {}
3132/// A draining iterator over the elements of an `InlineArray`.
33///
34/// "Draining" means that as the iterator yields each element, it's removed from
35/// the `InlineArray`. When the iterator terminates, the array will be empty.
36/// This is different from the consuming iterator `Iter` in that `Iter` will
37/// take ownership of the `InlineArray` and discard it when you're done
38/// iterating, while `Drain` leaves you still owning the drained `InlineArray`.
39pub struct Drain<'a, A, T> {
40pub(crate) array: &'a mut InlineArray<A, T>,
41}
4243impl<'a, A, T> Iterator for Drain<'a, A, T> {
44type Item = A;
4546fn next(&mut self) -> Option<Self::Item> {
47self.array.remove(0)
48 }
4950fn size_hint(&self) -> (usize, Option<usize>) {
51 (self.array.len(), Some(self.array.len()))
52 }
53}
5455impl<'a, A, T> DoubleEndedIterator for Drain<'a, A, T> {
56fn next_back(&mut self) -> Option<Self::Item> {
57self.array.pop()
58 }
59}
6061impl<'a, A, T> ExactSizeIterator for Drain<'a, A, T> {}
6263impl<'a, A, T> FusedIterator for Drain<'a, A, T> {}