#read-line #line #reader #fixed-size #interface #buffer

linebuf

The library provides a interface to read a line through a fixed size of buffer

2 releases

Uses old Rust 2015

0.0.2 Dec 25, 2017
0.0.1 Dec 22, 2017

#45 in #read-line

MIT license

6KB
113 lines

linebuf

The library provides a interface to read a line through a fixed size of buffer

Usage

Add this to your Cargo.toml:

[dependencies]
linebuf = "0.0.1"

And add this to your crate root:

extern crate linebuf

Example

extern crate linebuf;
use linebuf::{Line, LineReader};

let mut reader = LineReader::new(File::open("/path/to/file")?);
let mut buf = vec![0; 1024];
loop {
  match reader.try_read_line(&mut buf)? {
    Line::Return(0) => break, // EOF
    Line::Return(n) => {
      // reading data reached the `carriage return`(\n)
      ...
    }
    Line::More(n) => {
      // In this time, the data doesn't reached the end of line
      ...
    }
  }
}

Dependencies

~110–255KB