An open API service indexing awesome lists of open source software.

https://github.com/metastable-void/dropcatch-rs

Drop detection library for Rust
https://github.com/metastable-void/dropcatch-rs

rust rust-lifetime

Last synced: 3 months ago
JSON representation

Drop detection library for Rust

Awesome Lists containing this project

README

          

# Drop detection library for Rust
With Clone, Sync, Send and optional PartialEq + Hash support.

## Examples
```rust
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
```