stream_inmemory/
traits.rs

1use crate::StreamError;
2
3pub trait TWrite {
4    /// Write one byte to stream.
5    fn write_byte(&mut self, byte: u8);
6
7    /// Write bytes to stream.
8    fn write(&mut self, buffer: &[u8]) -> usize;
9}
10
11pub trait TRead {
12    /// Peek one byte from stream, position don't shift.
13    ///
14    /// Can return EOF error.
15    fn peek_byte(&self) -> Result<u8, StreamError>;
16
17    /// Peek bytes from stream, position don't shift.
18    ///
19    /// Can return EOF, ZeroLength errors.
20    fn peek(&self, buffer: &mut [u8]) -> Result<usize, StreamError>;
21
22    /// Read one byte from stream, position  shifted.
23    ///
24    /// Can return EOF error.
25    fn read_byte(&mut self) -> Result<u8, StreamError>;
26
27    /// Read bytes from stream, position shifted.
28    ///
29    /// Can return EOF, ZeroLength errors.
30    fn read(&mut self, buffer: &mut [u8]) -> Result<usize, StreamError>;
31
32    /// Skip "count" bytes in stream, position shifted.
33    fn skip(&mut self, count: usize) -> usize;
34
35    /// Skip all bytes in stream, position shifted.
36    fn skip_all(&mut self) -> usize;
37
38    /// View of available bytes in stream.
39    fn view(&self) -> &[u8];
40
41    /// Return available to read bytes.
42    fn available(&self) -> usize;
43}