expression
Flush a buffered async writer
Buffer small writes and explicitly flush before relying on the underlying writer. Dropping a Tokio BufWriter does not automatically flush pending bytes; flush does not mean durable storage or peer acknowledgment. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): 0 3 Common mistake: Dropping a buffered writer and assuming pending bytes were saved.
Formal Syntax & Structure
rust syntaxrust
BufWriter::new(writer); writer.flush().awaitWorking Example
Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() { use tokio::io::{AsyncWriteExt, BufWriter}; let mut out = BufWriter::with_capacity(16, Vec::new()); out.write_all(b"abc").await.unwrap(); println!("{}", out.get_ref().len()); out.flush().await.unwrap(); println!("{}", out.get_ref().len());}