std-method

BufWriter::into_inner: recover destination

Consume the wrapper and flush its buffer before returning the underlying destination. If flushing fails, the error retains the wrapper for recovery; do not silently discard that error. Expected stdout (not executed): done Common mistake: Assuming into_inner can never fail.

Formal Syntax & Structure

rust syntaxrust
writer.into_inner() -> Result<W, IntoInnerError<BufWriter<W>>>

Working Example

Example Snippetrust
fn main() {    use std::io::{BufWriter, Write};    let mut w = BufWriter::with_capacity(16, Vec::new());    w.write_all(b"done").unwrap();    let out = w.into_inner().unwrap();    println!("{}", String::from_utf8(out).unwrap());}
Rust Reference