Macro easy_ffi_wrapper::ffi_box
source · macro_rules! ffi_box { (@impl, $type:ident, $boxed_type:ident, new($func:path)) => { ... }; (@impl, $type:ident, $boxed_type:ident, clone($func:path)) => { ... }; ($type:ident, $boxed_type:ident, debug, delete($delete_func:path) $(, $func_type:ident($func:path))*) => { ... }; ($type:ident, $boxed_type:ident, delete($delete_func:path) $(, $func_type:ident($func:path))*) => { ... }; }
Expand description
Generates an owning type BoxedTypeName for a FFI type TypeName.
The generated type BoxedTypeName behaves like Box<TypeName> with a custom destructor.
Box types implement: Drop, Deref, DerefMut, AsRef, Borrow, Clone, Default.
Example
ⓘ
ffi_box!(
TypeName,
BoxedTypeName,
debug, // optional; omit if debug output is not supported
delete(bindings::type_name_release),
new(bindings::type_name_create), // optional default constructor
clone(bindings::type_name_clone) // optional copy constructor
);Rationale behind
If Rust’s built-in box type Box<T> had a facility to provide a custom destructor, we would not
need to generate such box types, since we could just use the built-in type.