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
use bytes::Bytes;

use std::collections::vec_deque;
use std::iter::FusedIterator;

/// The iterator produced by the `drain_chunks` method of `ChunkedBytes`.
pub struct DrainChunks<'a> {
    inner: vec_deque::Drain<'a, Bytes>,
}

impl<'a> DrainChunks<'a> {
    #[inline]
    pub(crate) fn new(inner: vec_deque::Drain<'a, Bytes>) -> Self {
        DrainChunks { inner }
    }
}

impl<'a> Iterator for DrainChunks<'a> {
    type Item = Bytes;

    #[inline]
    fn next(&mut self) -> Option<Bytes> {
        self.inner.next()
    }

    #[inline]
    fn size_hint(&self) -> (usize, Option<usize>) {
        self.inner.size_hint()
    }
}

impl<'a> ExactSizeIterator for DrainChunks<'a> {}
impl<'a> FusedIterator for DrainChunks<'a> {}

/// The iterator produced by the `into_chunks` method of `ChunkedBytes`.
pub struct IntoChunks {
    inner: vec_deque::IntoIter<Bytes>,
}

impl IntoChunks {
    #[inline]
    pub(crate) fn new(inner: vec_deque::IntoIter<Bytes>) -> Self {
        IntoChunks { inner }
    }
}

impl Iterator for IntoChunks {
    type Item = Bytes;

    #[inline]
    fn next(&mut self) -> Option<Bytes> {
        self.inner.next()
    }

    #[inline]
    fn size_hint(&self) -> (usize, Option<usize>) {
        self.inner.size_hint()
    }
}

impl ExactSizeIterator for IntoChunks {}
impl FusedIterator for IntoChunks {}