grit_bitvec/
const_proto_bitvec_iter.rs

1use crate::{
2    BitProto,
3    RawBitVecIter, 
4    RawBitVecDrain,
5};
6
7pub struct CProtoBitVecIter<const BIT_WIDTH: usize>(pub(crate) RawBitVecIter);
8
9impl<const BIT_WIDTH: usize> CProtoBitVecIter<BIT_WIDTH> {
10    pub(crate) const PROTO: BitProto = BitProto::create(BIT_WIDTH);
11}
12
13impl<const BIT_WIDTH: usize> Iterator for CProtoBitVecIter<BIT_WIDTH> {
14    type Item = usize;
15
16    fn next(&mut self) -> Option<Self::Item> {
17        unsafe {self.0.next(Self::PROTO)}
18    }
19
20    fn size_hint(&self) -> (usize, Option<usize>) {
21        let len = self.0.len();
22        (len, Some(len))
23    }
24}
25
26impl<const BIT_WIDTH: usize> DoubleEndedIterator for CProtoBitVecIter<BIT_WIDTH> {
27
28    fn next_back(&mut self) -> Option<Self::Item> {
29        unsafe {self.0.next_back(Self::PROTO)}
30    }
31}
32
33impl<const BIT_WIDTH: usize> ExactSizeIterator for CProtoBitVecIter<BIT_WIDTH> {
34
35    fn len(&self) -> usize {
36        self.0.len()
37    }
38}
39
40impl<const BIT_WIDTH: usize> Drop for CProtoBitVecIter<BIT_WIDTH>  {
41    fn drop(&mut self) {/* RawBitVecIter will handle the deallocation */}
42}
43
44pub struct CProtoBitVecDrain<'vec, const BIT_WIDTH: usize>(pub(crate) RawBitVecDrain<'vec>);
45
46impl <'vec, const BIT_WIDTH: usize> CProtoBitVecDrain<'vec, BIT_WIDTH> {
47    pub(crate) const PROTO: BitProto = BitProto::create(BIT_WIDTH);
48}
49
50impl<'vec, const BIT_WIDTH: usize> Iterator for CProtoBitVecDrain<'vec, BIT_WIDTH> {
51    type Item = usize;
52
53    fn next(&mut self) -> Option<Self::Item> {
54        unsafe {self.0.next(Self::PROTO)}
55    }
56
57    fn size_hint(&self) -> (usize, Option<usize>) {
58        let len = self.0.len();
59        (len, Some(len))
60    }
61}
62
63impl<'vec, const BIT_WIDTH: usize> DoubleEndedIterator for CProtoBitVecDrain<'vec, BIT_WIDTH> {
64
65    fn next_back(&mut self) -> Option<Self::Item> {
66        unsafe {self.0.next_back(Self::PROTO)}
67    }
68}
69
70impl<'vec, const BIT_WIDTH: usize> ExactSizeIterator for CProtoBitVecDrain<'vec, BIT_WIDTH> {
71
72    fn len(&self) -> usize {
73        self.0.len()
74    }
75}
76
77impl<'vec, const BIT_WIDTH: usize> Drop for CProtoBitVecDrain<'vec, BIT_WIDTH>  {
78    fn drop(&mut self) {/* RawBitVecIter will handle the deallocation */}
79}