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

read-to-timeout

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

5 unstable releases

0.3.1 Jan 16, 2025
0.3.0 Jan 16, 2025
0.2.0 Dec 30, 2024
0.1.4 Oct 11, 2022
0.1.3 Sep 15, 2022

#572 in Hardware support

Download history 5/week @ 2024-10-02 3/week @ 2024-12-11 98/week @ 2024-12-25 18/week @ 2025-01-01 7/week @ 2025-01-08 237/week @ 2025-01-15

360 downloads per month

MIT AND Apache-2.0

9KB
113 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_timeout_or_pattern that are implemented for all types that implements std::io::Read

Usage

ReadToTimeout::read_to_timeout

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

ReadToTimeout::read_to_timeout_or_bytes

read_to_timeout_or_bytes is similar to read_to_timeout

But when read byte count reaches given max_byte, this function returns Ok(bytes_read) immediately

ReadToTimeout::read_to_timeout_or_pattern

read_to_timeout_or_pattern is similar to read_to_timeout

But when a specified pattern is reached, 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.

No runtime deps