#dropped #run #object #closures #on-drop

no-std run-on-drop

Run code when an object is dropped

1 stable release

1.0.0 Apr 15, 2025

#1088 in Rust patterns

Download history 135/week @ 2025-04-11 212/week @ 2025-04-18 81/week @ 2025-04-25 126/week @ 2025-05-02 196/week @ 2025-05-09 42/week @ 2025-05-16 50/week @ 2025-05-23 25/week @ 2025-05-30 28/week @ 2025-06-06 42/week @ 2025-06-13 70/week @ 2025-06-20 76/week @ 2025-06-27 102/week @ 2025-07-04 241/week @ 2025-07-11 224/week @ 2025-07-18

649 downloads per month
Used in 3 crates (2 directly)

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