Crates.io | char_reader |
lib.rs | char_reader |
version | 0.1.1 |
source | src |
created_at | 2020-11-04 15:07:22.488275 |
updated_at | 2021-11-02 15:22:25.278714 |
description | Safely read wild streams as chars or lines |
homepage | |
repository | https://github.com/Canop/char_reader |
max_upload_size | |
id | 308619 |
size | 14,417 |
BufRead's read_line may be a problem when you need performance and safety on unvetted streams:
You may wait forever or get an out of memory panic if there's no newline in the stream. And even if there's one, it may be way past what you need: you'll have to keep everything in memory just to get to the start of the following line.
CharReader
is a buffered reader fixing those problems.
next_char
function to read only one charIt's suitable when you'd like to read UTF8 lines and aren't sure the data are kind enough.
When reading a line, you pass two parameters:
All errors are io::Error
:
InvalidData
Other
Alternative: If you know in advance how many lines you'd need and you always want whole lines, the standard take
method of BufReader
protects you against memory overflows.