Skip to main content

seize/
reclaim.rs

1//! Common memory reclaimers.
2//!
3//! The functions in this module can be passed to
4//! [`retire`](crate::Collector::retire) to free allocated memory or run drop
5//! glue. See [the guide](crate#custom-reclaimers) for details about memory
6//! reclamation, and writing custom reclaimers.
7
8use std::ptr;
9
10use crate::Collector;
11
12/// Reclaims memory allocated with [`Box`].
13///
14/// # Safety
15///
16/// The safety requirements of [`Box::from_raw`] apply.
17pub unsafe fn boxed<T>(ptr: *mut T, _collector: &Collector) {
18    unsafe { drop(Box::from_raw(ptr)) }
19}
20
21/// Reclaims memory by dropping the value in place.
22///
23/// # Safety
24///
25/// The safety requirements of [`ptr::drop_in_place`] apply.
26pub unsafe fn in_place<T>(ptr: *mut T, _collector: &Collector) {
27    unsafe { ptr::drop_in_place::<T>(ptr) }
28}