#read #io-read #serial-port #utility #behavior


Extension on std::io::Read trait where timeout is the expected behaviour

2 releases

0.1.4 Oct 11, 2022
0.1.3 Sep 15, 2022
0.1.2 Sep 15, 2022
0.1.1 Sep 15, 2022

#1350 in Hardware support

MIT AND Apache-2.0

62 lines

Read to Timeout

An extension trait for trait std::io::Read

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 provides read_to_timeout and read_to_pattern_or_timeout that are implemented for all types that implements std::io::Read



read_to_timeout behaves just like read_to_end, except on timeout, this method returns Ok(bytes_read) instead of Err(..)


read_to_pattern_or_timeout is similar to read_to_timeout

But when a specified pattern is reached, return Ok(bytes_read) immediately


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.

No runtime deps