expression
Reuse a line buffer explicitly
This method appends text including its newline when present. Clear a reused buffer between records. It is not cancellation-safe for a race that discards an unfinished read; consider Lines for that use case. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): a b Common mistake: Forgetting to clear the existing String between reads.
Formal Syntax & Structure
rust syntaxrust
reader.read_line(&mut text).awaitWorking Example
Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() { use tokio::io::{AsyncBufReadExt, BufReader}; let mut r = BufReader::new(&b"a\nb\n"[..]); let mut line = String::new(); while r.read_line(&mut line).await.unwrap() != 0 { println!("{}", line.trim_end_matches('\n')); line.clear(); }}