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

pub struct CProtoBitVecIter<const BIT_WIDTH: usize>(pub(crate) RawBitVecIter);

impl<const BIT_WIDTH: usize> CProtoBitVecIter<BIT_WIDTH> {
    pub(crate) const PROTO: BitProto = BitProto::create(BIT_WIDTH);
}

impl<const BIT_WIDTH: usize> Iterator for CProtoBitVecIter<BIT_WIDTH> {
    type Item = usize;

    fn next(&mut self) -> Option<Self::Item> {
        unsafe {self.0.next(Self::PROTO)}
    }

    fn size_hint(&self) -> (usize, Option<usize>) {
        let len = self.0.len();
        (len, Some(len))
    }
}

impl<const BIT_WIDTH: usize> DoubleEndedIterator for CProtoBitVecIter<BIT_WIDTH> {

    fn next_back(&mut self) -> Option<Self::Item> {
        unsafe {self.0.next_back(Self::PROTO)}
    }
}

impl<const BIT_WIDTH: usize> ExactSizeIterator for CProtoBitVecIter<BIT_WIDTH> {

    fn len(&self) -> usize {
        self.0.len()
    }
}

impl<const BIT_WIDTH: usize> Drop for CProtoBitVecIter<BIT_WIDTH>  {
    fn drop(&mut self) {/* RawBitVecIter will handle the deallocation */}
}

pub struct CProtoBitVecDrain<'vec, const BIT_WIDTH: usize>(pub(crate) RawBitVecDrain<'vec>);

impl <'vec, const BIT_WIDTH: usize> CProtoBitVecDrain<'vec, BIT_WIDTH> {
    pub(crate) const PROTO: BitProto = BitProto::create(BIT_WIDTH);
}

impl<'vec, const BIT_WIDTH: usize> Iterator for CProtoBitVecDrain<'vec, BIT_WIDTH> {
    type Item = usize;

    fn next(&mut self) -> Option<Self::Item> {
        unsafe {self.0.next(Self::PROTO)}
    }

    fn size_hint(&self) -> (usize, Option<usize>) {
        let len = self.0.len();
        (len, Some(len))
    }
}

impl<'vec, const BIT_WIDTH: usize> DoubleEndedIterator for CProtoBitVecDrain<'vec, BIT_WIDTH> {

    fn next_back(&mut self) -> Option<Self::Item> {
        unsafe {self.0.next_back(Self::PROTO)}
    }
}

impl<'vec, const BIT_WIDTH: usize> ExactSizeIterator for CProtoBitVecDrain<'vec, BIT_WIDTH> {

    fn len(&self) -> usize {
        self.0.len()
    }
}

impl<'vec, const BIT_WIDTH: usize> Drop for CProtoBitVecDrain<'vec, BIT_WIDTH>  {
    fn drop(&mut self) {/* RawBitVecIter will handle the deallocation */}
}