cogo_http/multipart/
byte_buf.rs

1use std::io::{Read, Write};
2
3pub struct ByteBuffer {
4    pub inner: Vec<u8>,
5}
6
7impl Write for ByteBuffer {
8    fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
9        for x in buf {
10            self.inner.push(x.clone());
11        }
12        Ok(buf.len())
13    }
14
15    fn flush(&mut self) -> std::io::Result<()> {
16        Ok(())
17    }
18}
19
20impl Read for ByteBuffer {
21    fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
22        let mut idx = 0;
23        for x in &self.inner {
24            if idx < buf.len() {
25                buf[idx] = x.clone();
26            } else {
27                break;
28            }
29            idx += 1;
30        }
31        Ok(idx)
32    }
33}