Struct linereader::LineReader

source ·
pub struct LineReader<R> { /* private fields */ }
Expand description

The LineReader struct adds buffered, byte-delimited (default: \n) reading to any io::Reader.

Implementations

Create a new LineReader around the reader with a default capacity of 64 KiB and delimiter of \n.

let reader = LineReader::new(File::open("myfile.txt")?);

Create a new LineReader around the reader with a given capacity and delimiter of \n.

let mut reader = LineReader::with_capacity(1024*512, File::open("myfile.txt")?);

Create a new LineReader around the reader with a default capacity of 1 MiB and the given delimiter.

let mut reader = LineReader::with_delimiter(b'\t', File::open("myfile.txt")?);

Create a new LineReader around the reader with a given capacity and delimiter.

let mut reader = LineReader::with_delimiter_and_capacity(b'\t', 1024*512, File::open("myfile.txt")?);

Get the next line from the reader, an IO error, or None on EOF. The delimiter is included in any returned slice, unless the file ends without one or a line was truncated to the buffer size due to length.

while let Some(line) = reader.next_line() {
    let line = line?;  // unwrap io::Result to &[u8]
}

Return a slice of complete lines, up to the size of the internal buffer.

This is functionally identical to next_line, only instead of getting up to the first instance of the delimiter, you get up to the last.

while let Some(lines) = reader.next_batch() {
    let lines = lines?;  // unwrap io::Result to &[u8]
}

Reset the internal state of the buffer. Next lines are read from wherever the reader happens to be.

Get a reference to the reader.

Get a mutable reference to the reader.

Unwrap this LineReader, returning the underlying reader and discarding any unread buffered lines.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.