Macro ffi_support::define_box_destructor
source · macro_rules! define_box_destructor {
($T:ty, $destructor_name:ident) => { ... };
}
Expand description
Define a (public) destructor for a type that was allocated by Box::into_raw(Box::new(value))
(e.g. a pointer which is probably opaque).
Caveats
This can go wrong in a ridiculous number of ways, and we can’t really prevent any of them. But essentially, the caller (on the other side of the FFI) needs to be extremely careful to ensure that it stops using the pointer after it’s freed.
Also, to avoid name collisions, it is strongly recommended that you provide an name for this function unique to your library. (This is true for all functions you expose).
Example
struct CoolType(Vec<i32>);
define_box_destructor!(CoolType, mylib_destroy_cooltype);