#raii #cleanup


RAII wrapper for non-RAII objects

1 unstable release

0.8.0 Jul 11, 2020

#8 in #cleanup

0BSD license



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();

  // .. do things ..

  // /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.

No runtime deps