#detect #drop #mutex #arc #partial-eq #hash

dropcatch

Drop detection library for Rust

3 releases (breaking)

Uses new Rust 2024

0.3.0 Oct 12, 2025
0.2.0 Oct 12, 2025
0.1.0 Oct 12, 2025

#15 in #drop


Used in iphost

Apache-2.0 OR MPL-2.0

12KB
86 lines

Drop detection library for Rust

With Clone, Sync, Send and optional PartialEq + Hash support.

Examples

use std::sync::{Arc, Mutex};
use dropcatch::DropCatcher;

// flag to track the dropped state
let flag = Arc::new(Mutex::new(false));
let flag_clone = flag.clone();

{
    let dropped = DropCatcher::new(move || {
        // called when DropCatcher is dropped
        *flag_clone.lock().unwrap() = true;
    });

    let dropped_clone = dropped.clone();

    assert_eq!(dropped, dropped_clone); // same instance

    drop(dropped);
    assert!(!*flag.lock().unwrap()); // not still dropped
}

assert!(*flag.lock().unwrap()); // dropped

Dependencies

~88KB