Expand description
A helper crate for testing drop-semantics (i.e. whether or not a value was or as not dropped as expected).
§Examples
Ensure std::mem::drop
does in fact drop:
use droptest::prelude::*;
let registry = DropRegistry::default();
let guard = registry.new_guard();
let guard_id = guard.id();
std::mem::drop(guard);
assert_drop!(registry, guard_id);
Ensure std::mem::forget
does not drop:
use droptest::prelude::*;
let registry = DropRegistry::default();
let guard = registry.new_guard();
let guard_id = guard.id();
std::mem::forget(guard);
assert_no_drop!(registry, guard_id);
Ensure std::rc::Rc
only drops the when reference count reaches 0
:
use droptest::prelude::*;
let registry = DropRegistry::default();
let guard = registry.new_guard();
let guard_id = guard.id();
let rc = std::rc::Rc::new(guard);
let rc_clone = rc.clone();
std::mem::drop(rc);
assert_no_drop!(registry, guard_id);
std::mem::drop(rc_clone);
assert_drop!(registry, guard_id);
Modules§
- prelude
- The doptest prelude.
Macros§
- assert_
drop - Asserts that the registry has registered a drop for the given id.
- assert_
drop_ stats - Asserts that the registry’s current stats match the provided pattern.
- assert_
no_ drop - Asserts that the registry has not registered a drop for the given id.
Structs§
- Drop
Guard - A guard object that reports to its registry when it gets dropped.
- Drop
Guard Id - An identifier associated with a registry’s individual registered guards.
- Drop
Registry - A registry for tracking a guard’s liveness state (i.e. alive vs. dropped).
- Drop
Statistics - A snapshot for a registry’s statistics at a given time.