    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

    use alloc::collections::VecDeque;
    #[cfg(feature = "std")]
    use std::io;

    use super::Buf;

    impl Buf for VecDeque<u8> {
        fn remaining(&self) -> usize {
            self.len()
        }

        fn chunk(&self) -> &[u8] {
            let (s1, s2) = self.as_slices();
            if s1.is_empty() {
                s2
            } else {
                s1
            }
        }

        #[cfg(feature = "std")]
        fn chunks_vectored<'a>(&'a self, dst: &mut [io::IoSlice<'a>]) -> usize {
            if self.is_empty() || dst.is_empty() {
                return 0;
            }

            let (s1, s2) = self.as_slices();
            dst[0] = io::IoSlice::new(s1);
            if s2.is_empty() || dst.len() == 1 {
                return 1;
            }

            dst[1] = io::IoSlice::new(s2);
            2
        }

        fn advance(&mut self, cnt: usize) {
            self.drain(..cnt);
        }
    }