std-method
BufRead::read_line: append a line
Append one UTF-8 line, retaining its newline when present. Clear a reused string between records. A zero byte count indicates EOF; a blank line normally contains a newline byte. Expected stdout (not executed): 2 "a\n" 1 "\n" 1 "b" 0 "" Common mistake: Confusing a blank line with EOF or forgetting to clear the string.
Formal Syntax & Structure
rust syntaxrust
reader.read_line(&mut String) -> io::Result<usize>Working Example
Example Snippetrust
fn main() { use std::io::BufRead; let mut r = &b"a b"[..]; let mut line = String::new(); for _ in 0..4 { line.clear(); let n = r.read_line(&mut line).unwrap(); println!("{n} {:?}", line); }}