#dropped #on-drop #run-on-drop

no-std run-on-drop

Run code when an object is dropped

1 stable release

new 1.0.0 Apr 15, 2025

#464 in No standard library

MIT/Apache

6KB
95 lines

This crate provides a closure wrapper that will run the closure when it is dropped.

See on_drop for examples.


run-on-drop

crates.io docs.rs MSRV

This crate provides a closure wrapper that will run the closure when it is dropped.

Example

use run_on_drop::on_drop;

let object = create_object();
let cleanup = on_drop(|| destroy_object(&object));
initialize_object(&object); // might unwind
cleanup.forget();
return object;

MSRV

The MSRV is max(stable - 3).

License

This project is licensed under either of

  • Apache License, Version 2.0
  • MIT License

at your option.

No runtime deps