std-method
Write::flush: surface buffered errors
Explicit flushing is useful at message boundaries and before returning success from buffered output. A successful flush is not equivalent to an fsync or acknowledgement from a remote peer. Expected stdout (not executed): 0 2 Common mistake: Relying on the destructor to report errors.
Formal Syntax & Structure
rust syntaxrust
writer.flush() -> io::Result<()>Working Example
Example Snippetrust
fn main() { use std::io::{BufWriter, Write}; let mut writer = BufWriter::with_capacity(16, Vec::new()); writer.write_all(b"ok").unwrap(); println!("{}", writer.get_ref().len()); writer.flush().unwrap(); println!("{}", writer.get_ref().len());}