chunked_bytes/
iter.rs

1use bytes::Bytes;
2
3use std::collections::vec_deque;
4use std::iter::FusedIterator;
5
6/// The iterator produced by the `drain_chunks` method of `ChunkedBytes`.
7pub struct DrainChunks<'a> {
8    inner: vec_deque::Drain<'a, Bytes>,
9}
10
11impl<'a> DrainChunks<'a> {
12    #[inline]
13    pub(crate) fn new(inner: vec_deque::Drain<'a, Bytes>) -> Self {
14        DrainChunks { inner }
15    }
16}
17
18impl<'a> Iterator for DrainChunks<'a> {
19    type Item = Bytes;
20
21    #[inline]
22    fn next(&mut self) -> Option<Bytes> {
23        self.inner.next()
24    }
25
26    #[inline]
27    fn size_hint(&self) -> (usize, Option<usize>) {
28        self.inner.size_hint()
29    }
30}
31
32impl<'a> ExactSizeIterator for DrainChunks<'a> {}
33impl<'a> FusedIterator for DrainChunks<'a> {}
34
35/// The iterator produced by the `into_chunks` method of `ChunkedBytes`.
36pub struct IntoChunks {
37    inner: vec_deque::IntoIter<Bytes>,
38}
39
40impl IntoChunks {
41    #[inline]
42    pub(crate) fn new(inner: vec_deque::IntoIter<Bytes>) -> Self {
43        IntoChunks { inner }
44    }
45}
46
47impl Iterator for IntoChunks {
48    type Item = Bytes;
49
50    #[inline]
51    fn next(&mut self) -> Option<Bytes> {
52        self.inner.next()
53    }
54
55    #[inline]
56    fn size_hint(&self) -> (usize, Option<usize>) {
57        self.inner.size_hint()
58    }
59}
60
61impl ExactSizeIterator for IntoChunks {}
62impl FusedIterator for IntoChunks {}