close-file 0.1.0

Allows to close a file without silently dropping errors
Documentation
  • Coverage
  • 50%
    3 out of 6 items documented1 out of 6 items with examples
  • Size
  • Source code size: 6.94 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 24s Average build duration of successful builds.
  • all releases: 24s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • AndreKR

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.