Trait BufReadExt

Source
pub trait BufReadExt: BufRead {
    // Provided method
    fn lines_with_endings(self) -> LinesSplitEndings<Self> 
       where Self: Sized { ... }
}
Expand description

Extension trait that adds the lines_with_endings() method to any BufRead implementation.

§Examples

use std::io::Cursor;
use frep_core::line_reader::BufReadExt;

let cursor = Cursor::new(b"hello\nworld\r\n");

for line_result in cursor.lines_with_endings() {
    let (content, ending) = line_result?;
    println!("Content: '{}', Ending: '{:?}'", String::from_utf8_lossy(&content), ending);
}

Provided Methods§

Source

fn lines_with_endings(self) -> LinesSplitEndings<Self>
where Self: Sized,

Returns an iterator that yields lines with their endings preserved.

Each item yielded by the iterator is a Result<(Vec<u8>, LineEnding), io::Error> where the first element is the line content as bytes and the second is the line ending type.

Implementors§