[−][src]Crate io_close
An extension trait for safely dropping I/O writers
such as File
and
BufWriter
. Specifically, it is for I/O
writers which contain a resource handle (such as a raw file
descriptor), and where the automatic process of closing this handle
during drop may generate an unseen I/O error. Using this trait
(called Close
) these errors can be seen and dealt with.
In the case of Linux the man page for close(2) has the following to say:
Not checking the return value of close() is a common but nevertheless serious programming error. It is quite possible that errors on a previous write(2) operation are first reported at the final close(). Not checking the return value when closing the file may lead to silent loss of data. This can especially be observed with NFS and with disk quota.
Provided implementations of Close
are for standard library I/O
writers containing a raw file descriptor (Unix) or a raw handle or
raw socket (Windows).
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()?; // safely drop buffer and its contained File Ok(()) }
Modules
fs | Filesystem manipulation operations. |
Traits
Close | An extension trait for safely dropping I/O writers containing a resource handle. |