[][src]Macro ffi_support::define_box_destructor

macro_rules! define_box_destructor {
    ($T:ty, $destructor_name:ident) => { ... };
}

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

When called over the FFI, 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).

However, when called from rust, this is safe, as it becomes a function that just drops a Option<Box<T>> with some panic handling.

Example

struct CoolType(Vec<i32>);

define_box_destructor!(CoolType, mylib_destroy_cooltype);