orx_selfref_col/references/iter/
array_left_most_ptr.rs

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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use crate::{NodePtr, Variant};

/// Iterator for active references of an [`RefsArrayLeftMost`] collection,
/// which can be created by its `iter` method.
///
/// [`RefsArrayLeftMost`]: crate::RefsArrayLeftMost
pub struct ArrayLeftMostPtrIter<'a, V: Variant> {
    iter: core::slice::Iter<'a, Option<NodePtr<V>>>,
}

impl<'a, V: Variant> ArrayLeftMostPtrIter<'a, V> {
    pub(crate) fn new(iter: core::slice::Iter<'a, Option<NodePtr<V>>>) -> Self {
        Self { iter }
    }
}

impl<V: Variant> Default for ArrayLeftMostPtrIter<'_, V> {
    fn default() -> Self {
        Self {
            iter: Default::default(),
        }
    }
}

impl<'a, V: Variant> Iterator for ArrayLeftMostPtrIter<'a, V> {
    type Item = &'a NodePtr<V>;

    #[inline(always)]
    fn next(&mut self) -> Option<Self::Item> {
        self.iter.next().and_then(|x| x.as_ref())
    }

    #[inline(always)]
    fn size_hint(&self) -> (usize, Option<usize>) {
        let len = self.iter.len();
        (len, Some(len))
    }
}

impl<V: Variant> ExactSizeIterator for ArrayLeftMostPtrIter<'_, V> {
    #[inline(always)]
    fn len(&self) -> usize {
        self.iter.len()
    }
}

impl<V: Variant> DoubleEndedIterator for ArrayLeftMostPtrIter<'_, V> {
    fn next_back(&mut self) -> Option<Self::Item> {
        self.iter.next_back().and_then(|x| x.as_ref())
    }
}

// mut

/// Mutable iterator for active references of an [`RefsArrayLeftMost`] collection,
/// which can be created by its `iter_mut` method.
///
/// [`RefsArrayLeftMost`]: crate::RefsArrayLeftMost
pub struct ArrayLeftMostPtrIterMut<'a, V: Variant> {
    iter: core::slice::IterMut<'a, Option<NodePtr<V>>>,
}

impl<'a, V: Variant> ArrayLeftMostPtrIterMut<'a, V> {
    pub(crate) fn new(iter: core::slice::IterMut<'a, Option<NodePtr<V>>>) -> Self {
        Self { iter }
    }
}

impl<V: Variant> Default for ArrayLeftMostPtrIterMut<'_, V> {
    fn default() -> Self {
        Self {
            iter: Default::default(),
        }
    }
}

impl<'a, V: Variant> Iterator for ArrayLeftMostPtrIterMut<'a, V> {
    type Item = &'a mut NodePtr<V>;

    #[inline(always)]
    fn next(&mut self) -> Option<Self::Item> {
        self.iter.next().and_then(|x| x.as_mut())
    }

    #[inline(always)]
    fn size_hint(&self) -> (usize, Option<usize>) {
        let len = self.iter.len();
        (len, Some(len))
    }
}

impl<V: Variant> ExactSizeIterator for ArrayLeftMostPtrIterMut<'_, V> {
    #[inline(always)]
    fn len(&self) -> usize {
        self.iter.len()
    }
}

impl<V: Variant> DoubleEndedIterator for ArrayLeftMostPtrIterMut<'_, V> {
    fn next_back(&mut self) -> Option<Self::Item> {
        self.iter.next_back().and_then(|x| x.as_mut())
    }
}