#file #error #dropping #close #io #happen #silently

close-file

Allows to close a file without silently dropping errors

1 unstable release

0.1.0 Apr 4, 2020

#7 in #close

Download history 4/week @ 2024-11-13 3/week @ 2024-12-04 11/week @ 2024-12-11 1/week @ 2024-12-18 8/week @ 2025-02-05 21/week @ 2025-02-12 23/week @ 2025-02-19 44/week @ 2025-02-26

96 downloads per month

MIT license

5KB
66 lines

Allows to close a file without silently dropping errors

Errors can happen when closing a file, indicating that the file was not (completely) written. The standard library currently simply discards such error when the std::io::File goes out of scope.

This crate allows to close the file and handle potential errors.

use close_file::Closable;
use std::io::Write;

let mut f = std::fs::File::create("temp").unwrap();
f.write_all("Hello, world!".as_bytes());
f.close();

The close() function consumes the File. However, on Windows, a failed close operation may be retried. For this case the returned CloseError contains the original File.

Dependencies

~220KB