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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use super::abstract_mut::AbstractMut;
use super::mixed::Mixed;
use super::tight::Tight;
use super::with_id::LastId;
use crate::entity_id::EntityId;

#[allow(missing_docs)]
pub enum Iter<Storage> {
    Tight(Tight<Storage>),
    Mixed(Mixed<Storage>),
}

impl<Storage: AbstractMut> Iterator for Iter<Storage>
where
    <Storage as AbstractMut>::Index: Clone,
{
    type Item = Storage::Out;

    #[inline]
    fn next(&mut self) -> Option<Self::Item> {
        match self {
            Iter::Tight(tight) => tight.next(),
            Iter::Mixed(mixed) => mixed.next(),
        }
    }
    #[inline]
    fn size_hint(&self) -> (usize, Option<usize>) {
        match self {
            Iter::Tight(tight) => tight.size_hint(),
            Iter::Mixed(mixed) => mixed.size_hint(),
        }
    }
    #[inline]
    fn fold<B, F>(self, init: B, f: F) -> B
    where
        Self: Sized,
        F: FnMut(B, Self::Item) -> B,
    {
        match self {
            Iter::Tight(tight) => tight.fold(init, f),
            Iter::Mixed(mixed) => mixed.fold(init, f),
        }
    }
}

impl<Storage: AbstractMut> DoubleEndedIterator for Iter<Storage>
where
    <Storage as AbstractMut>::Index: Clone,
{
    #[inline]
    fn next_back(&mut self) -> Option<Self::Item> {
        match self {
            Iter::Tight(tight) => tight.next_back(),
            Iter::Mixed(mixed) => mixed.next_back(),
        }
    }
    #[inline]
    fn rfold<B, F>(self, init: B, f: F) -> B
    where
        Self: Sized,
        F: FnMut(B, Self::Item) -> B,
    {
        match self {
            Iter::Tight(tight) => tight.rfold(init, f),
            Iter::Mixed(mixed) => mixed.rfold(init, f),
        }
    }
}

impl<Storage: AbstractMut> LastId for Iter<Storage> {
    #[inline]
    unsafe fn last_id(&self) -> EntityId {
        match self {
            Iter::Tight(tight) => tight.last_id(),
            Iter::Mixed(mixed) => mixed.last_id(),
        }
    }
    #[inline]
    unsafe fn last_id_back(&self) -> EntityId {
        match self {
            Iter::Tight(tight) => tight.last_id_back(),
            Iter::Mixed(mixed) => mixed.last_id_back(),
        }
    }
}