eztd_core/string/
bytes.rs1pub struct Bytes {
2 buffer: super::String,
3 index: usize,
4}
5
6impl Bytes {
7 pub(super) fn new(buffer: super::String) -> Self {
8 Self { buffer, index: 0 }
9 }
10}
11
12impl Iterator for Bytes {
13 type Item = u8;
14
15 #[inline]
16 fn next(&mut self) -> Option<Self::Item> {
17 if self.index < self.buffer.byte_len() {
18 let current = self.index;
19 self.index += 1;
20 Some(self.buffer.as_str().as_bytes()[current])
21 } else {
22 None
23 }
24 }
25
26 #[inline]
27 fn size_hint(&self) -> (usize, Option<usize>) {
28 let len = self.buffer.byte_len();
29 (len, Some(len))
30 }
31}
32
33impl ExactSizeIterator for Bytes {
34 #[inline]
35 fn len(&self) -> usize {
36 self.buffer.byte_len()
37 }
38}
39
40impl std::iter::FusedIterator for Bytes {}