lines
is a small library to efficiently parse text files line by
line while avoiding unnecessary memory allocations.
Typically, processing log files or other line oriented file formats, doesn't always require allocation of memory for each processed line. Instead, we can ...
By re-using a buffer and having the client decide whether or not to make a copy of the read line, we can gain significant performance wins in certain situations.
Since lines
uses Cargo, adding a dependency
section as follows should suffice to start using it:
toml
[dependencies.lines]
version = "*"
The typical example of iterating a file line by line can be demonstrated with the following program:
```rust
extern crate lines;
use lines::linereader::LineReader; use std::fs::File; use std::str::from_utf8;
fn main() { let f = File::open("main.rs").unwrap(); readlines!(line in LineReader::new(f), { let line = fromutf8(line.unwrap()).unwrap(); print!("{}", line); }); }
```
There are certain limitations to the data that the library can process. Namely, a newline is assumed to be defined by '\n'. For more information can be found in the generated documentation of the library.