#error #file #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

#6 in #close

Download history 38/week @ 2023-12-29 32/week @ 2024-01-05 26/week @ 2024-01-12 2/week @ 2024-01-19 7/week @ 2024-01-26 15/week @ 2024-02-02 2/week @ 2024-02-09 41/week @ 2024-02-16 65/week @ 2024-02-23 37/week @ 2024-03-01 63/week @ 2024-03-08 59/week @ 2024-03-15 36/week @ 2024-03-22 34/week @ 2024-03-29 19/week @ 2024-04-05

162 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

~215KB