std-method

BufRead::lines: iterate text records

Each item is a Result<String>. Line terminators LF and CRLF are removed; a final line without a terminator is still returned. This is not a parser for quoted CSV records. Expected stdout (not executed): red blue last Common mistake: Assuming line iteration handles arbitrary record formats.

Formal Syntax & Structure

rust syntaxrust
reader.lines() -> Lines<Self>

Working Example

Example Snippetrust
fn main() {    use std::io::BufRead;    let r = &b"red    blue    last"[..];    for line in r.lines() { println!("{}", line.unwrap()); }}
Rust Reference