Skip to content

metastable-void/dropcatch-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Drop detection library for Rust

Topics

Resources

License

Apache-2.0, MPL-2.0 licenses found

Licenses found

Apache-2.0
LICENSE.APACHE
MPL-2.0
LICENSE.MPL

Stars

Watchers

Forks

Languages