trait
io::Write: output contract
A writer accepts bytes and may accept fewer than requested. Its flush operation asks it to move buffered data onward; this is not a universal durability guarantee. Expected stdout (not executed): 2 2 Common mistake: Treating a successful write as proof of a complete message or durable storage.
Formal Syntax & Structure
rust syntaxrust
fn write(&mut self, buf: &[u8]) -> io::Result<usize>; fn flush(&mut self) -> io::Result<()>Working Example
Example Snippetrust
fn main() { use std::io::Write; let mut dest = Vec::new(); let n = dest.write(b"hi").unwrap(); dest.flush().unwrap(); println!("{n} {}", dest.len());}