1 unstable release
0.8.0 | Jul 11, 2020 |
---|
#15 in #raii
4KB
Simple library for cleaning up non-RIAA resources using RIAA.
A function that needs to clean up resources automatically can create an AutoCleanup object that will clean up those resources automatically.
use std::path::Path;
use autocleanup::AutoCleanup;
fn do_something() -> Result<(), std::io::Error> {
let mut ac = AutoCleanup::new();
ac.push_file("/tmp/foo.sock");
// .. do things ..
Ok(())
// /tmp/foo.sock will automatically be removed as the function
// returns.
}
Be mindful of the Drop
trait caveats; for instance calling
std::process::exit()
will cause Drop traits not to run.
Because the cleanup occurs at Drop there's no error handling for failed cleanups -- errors will be silently ignored.