[][src]Crate io_close

An extension trait (Close) for safely closing I/O related types such as File and BufWriter. Specifically, it is for types containing a resource handle (such as a file descriptor) which, when closed, may return an I/O error.

Provided implementations are for standard library types which implement (or contain types which implement):

Using Close enables the handling or reporting of I/O errors which might otherwise be ignored during drop.

BufWriter example

use std::io::{BufWriter, Result, Write};
use io_close::Close;

fn main() -> Result<()> {
    let data = b"hello world";
    let mut buffer = BufWriter::new(tempfile::tempfile()?);
    buffer.write_all(data)?;
    buffer.close()?; // consume and close buffer and its contained File
    Ok(())
}

Modules

fs

Filesystem manipulation operations.

Traits

Close

An extension trait for safely closing I/O related types containing a resource handle which, when closed, may return an I/O error.