| 1 |
|
| 2 |
|
| 3 |
use std::fmt; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#[derive(Clone, Eq, PartialEq)] |
| 14 |
pub enum StreamIo { |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
Read(Result<StreamOutput, Vec<u8>>), |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
Write(Result<StreamOutput, Vec<u8>>), |
| 28 |
} |
| 29 |
|
| 30 |
impl fmt::Debug for StreamIo { |
| 31 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 32 |
match self { |
| 33 |
Self::Read(Ok(_)) => f.write_str("read output"), |
| 34 |
Self::Read(Err(_)) => f.write_str("read input"), |
| 35 |
|
| 36 |
Self::Write(Ok(_)) => f.write_str("write output"), |
| 37 |
Self::Write(Err(_)) => f.write_str("write input"), |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
#[derive(Clone, Debug, Eq, PartialEq)] |
| 44 |
pub struct StreamOutput { |
| 45 |
|
| 46 |
pub buffer: Vec<u8>, |
| 47 |
|
| 48 |
|
| 49 |
pub bytes_count: usize, |
| 50 |
} |
| 51 |
|
| 52 |
impl StreamOutput { |
| 53 |
|
| 54 |
pub fn bytes(&self) -> &[u8] { |
| 55 |
&self.buffer[..self.bytes_count] |
| 56 |
} |
| 57 |
} |