https://github.com/lpenz/lineriver
Non-blocking buffered line reader for Read objects
https://github.com/lpenz/lineriver
Last synced: 3 days ago
JSON representation
Non-blocking buffered line reader for Read objects
- Host: GitHub
- URL: https://github.com/lpenz/lineriver
- Owner: lpenz
- License: mit
- Created: 2023-07-16T21:24:46.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-18T21:26:23.000Z (about 1 year ago)
- Last Synced: 2025-05-04T09:39:47.171Z (14 days ago)
- Language: Rust
- Size: 35.2 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/lpenz/lineriver/actions/workflows/ci.yml)
[](https://coveralls.io/github/lpenz/lineriver?branch=main)
[](https://crates.io/crates/lineriver)
[](https://docs.rs/lineriver)# lineriver
**lineriver** is a rust crate that provides a non-blocking buffered line
reader for [`Read`] objects.The [`LineReader`] object is akin to a [`BufReader`] object
that returns only complete lines, but without blocking.
The [`LineRead`] trait, on the other hand, is akin to the
[`BufRead`] trait - it concentrates the public API and allows us
to create agnostic collections of LineReaders with distinct
underlying types.This crate works very well with the [polling] crate, which allows
us to block waiting on data to be available in any one of multiple
streams (files, sockets, etc.). It's an alternative to using
threads and/or [tokio].See [`LineReader`] for details.
## Usage
The simplest way to explain how to use `LineReader` is
with a busy-loop example:```rust
use lineriver::{LineReader, LineRead};let mut linereader = LineReader::new(reader)?;
while !linereader.eof() {
linereader.read_available()?;
let lines = linereader.lines_get();
for line in lines {
print!("{}", line);
}
}
```[`LineReader`]: https://docs.rs/lineriver/latest/lineriver/linereader/struct.LineReader.html
[`LineRead`]: https://docs.rs/lineriver/latest/lineriver/lineread/trait.LineRead.html
[`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
[`BufReader`]: https://doc.rust-lang.org/std/io/struct.BufReader.html
[`BufRead`]: https://doc.rust-lang.org/std/io/trait.BufRead.html
[`read_line`]: https://doc.rust-lang.org/std/io/trait.BufRead.html#method.read_line
[polling]: https://docs.rs/polling/latest/polling/index.html
[tokio]: https://tokio.rs/
[github]: https://github.com/lpenz/lineriver
[`tcp_line_echo`]: https://github.com/lpenz/lineriver/blob/main/examples/tcp_line_echo.rs