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
use crate::{
    BitProto,
    RawBitVecIter, 
    RawBitVecDrain,
};

pub struct SProtoBitVecIter {
    pub(crate) proto: &'static BitProto,
    pub(crate) iter: RawBitVecIter
}

impl Iterator for SProtoBitVecIter {
    type Item = usize;

    #[inline(always)]
    fn next(&mut self) -> Option<Self::Item> {
        unsafe {self.iter.next(*self.proto)}
    }

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

impl DoubleEndedIterator for SProtoBitVecIter {
    #[inline(always)]
    fn next_back(&mut self) -> Option<Self::Item> {
        unsafe {self.iter.next_back(*self.proto)}
    }
}

impl ExactSizeIterator for SProtoBitVecIter {
    #[inline(always)]
    fn len(&self) -> usize {
        self.iter.len()
    }
}

impl Drop for SProtoBitVecIter  {
    #[inline(always)]
    fn drop(&mut self) {/* RawBitVecIter will handle the deallocation */}
}

pub struct SProtoBitVecDrain<'vec>{
    pub(crate) proto: &'static BitProto,
    pub(crate) drain: RawBitVecDrain<'vec>
}

impl<'vec> Iterator for SProtoBitVecDrain<'vec> {
    type Item = usize;

    #[inline(always)]
    fn next(&mut self) -> Option<Self::Item> {
        unsafe {self.drain.next(*self.proto)}
    }

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

impl<'vec> DoubleEndedIterator for SProtoBitVecDrain<'vec> {
    #[inline(always)]
    fn next_back(&mut self) -> Option<Self::Item> {
        unsafe {self.drain.next_back(*self.proto)}
    }
}

impl<'vec> ExactSizeIterator for SProtoBitVecDrain<'vec> {
    #[inline(always)]
    fn len(&self) -> usize {
        self.drain.len()
    }
}

impl<'vec> Drop for SProtoBitVecDrain<'vec>  {
    #[inline(always)]
    fn drop(&mut self) {/* RawBitVecIter will handle the deallocation */}
}