pub trait ReadToTimeout {
// Required methods
fn read_to_timeout(&mut self, buf: &mut Vec<u8>) -> Result<usize>;
fn read_to_timeout_or_bytes(
&mut self,
buf: &mut Vec<u8>,
max_byte: usize,
) -> Result<usize>;
fn read_to_timeout_or_pattern(
&mut self,
buf: &mut Vec<u8>,
pattern: &[u8],
) -> Result<usize>;
fn read_to_pattern_or_timeout(
&mut self,
buf: &mut Vec<u8>,
pattern: &[u8],
) -> Result<usize>;
}
Expand description
The std::io::Read trait implements many read operations, but it doesn’t contain a simple read method where timeout is the expected behaviour
This trait is implemented for all types that implements std::io::Read, provides read_to_timeout, read_to_timeout_or_bytes, and read_to_timeout_or_pattern
Required Methods§
Sourcefn read_to_timeout(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_timeout(&mut self, buf: &mut Vec<u8>) -> Result<usize>
Similar to read_to_end
But when timeout, instead of returning error, this function returns
Ok(bytes_read)
Sourcefn read_to_timeout_or_bytes(
&mut self,
buf: &mut Vec<u8>,
max_byte: usize,
) -> Result<usize>
fn read_to_timeout_or_bytes( &mut self, buf: &mut Vec<u8>, max_byte: usize, ) -> Result<usize>
Similar to read_to_timeout
But when the received byte count reaches max_byte
, this function
returns Ok(bytes_read)
immediately
Sourcefn read_to_timeout_or_pattern(
&mut self,
buf: &mut Vec<u8>,
pattern: &[u8],
) -> Result<usize>
fn read_to_timeout_or_pattern( &mut self, buf: &mut Vec<u8>, pattern: &[u8], ) -> Result<usize>
Similar to read_to_timeout
But when a specified pattern is reached, this function return
Ok(bytes_read)
immediately
§Note
If the provided buffer is non-empty, while at least one byte must be read before any pattern match, it is possible for pattern to match on old bytes.
Sourcefn read_to_pattern_or_timeout(
&mut self,
buf: &mut Vec<u8>,
pattern: &[u8],
) -> Result<usize>
👎Deprecated
fn read_to_pattern_or_timeout( &mut self, buf: &mut Vec<u8>, pattern: &[u8], ) -> Result<usize>
DEPRECATED
Use read_to_timeout_or_pattern instead