scanner-rust 3.0.1

Simple text scanners which can parse primitive types and strings using UTF-8 or ASCII.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use std::io::{self, ErrorKind, Read};

#[inline]
pub(crate) fn read<R: Read>(reader: &mut R, buffer: &mut [u8]) -> io::Result<usize> {
    loop {
        match reader.read(buffer) {
            Ok(size) if size <= buffer.len() => return Ok(size),
            Ok(_) => {
                return Err(io::Error::new(
                    ErrorKind::InvalidData,
                    "reader returned more bytes than the buffer can hold",
                ));
            },
            Err(err) if err.kind() == ErrorKind::Interrupted => (),
            Err(err) => return Err(err),
        }
    }
}