1 | use alloc::collections::VecDeque; |
2 | #[cfg (feature = "std" )] |
3 | use std::io; |
4 | |
5 | use super::Buf; |
6 | |
7 | impl Buf for VecDeque<u8> { |
8 | fn remaining(&self) -> usize { |
9 | self.len() |
10 | } |
11 | |
12 | fn chunk(&self) -> &[u8] { |
13 | let (s1, s2) = self.as_slices(); |
14 | if s1.is_empty() { |
15 | s2 |
16 | } else { |
17 | s1 |
18 | } |
19 | } |
20 | |
21 | #[cfg (feature = "std" )] |
22 | fn chunks_vectored<'a>(&'a self, dst: &mut [io::IoSlice<'a>]) -> usize { |
23 | if self.is_empty() || dst.is_empty() { |
24 | return 0; |
25 | } |
26 | |
27 | let (s1, s2) = self.as_slices(); |
28 | dst[0] = io::IoSlice::new(s1); |
29 | if s2.is_empty() || dst.len() == 1 { |
30 | return 1; |
31 | } |
32 | |
33 | dst[1] = io::IoSlice::new(s2); |
34 | 2 |
35 | } |
36 | |
37 | fn advance(&mut self, cnt: usize) { |
38 | self.drain(..cnt); |
39 | } |
40 | } |
41 | |