Attribute proc macro that can be used to turn a dyn-compatible trait definition into a C++ compatible vtable definition.
Mainly intended for making mods/memory hacking C++ applications.
For a usage example, say we have a C++ abstract class of the form
;
This macro then allows us to represent Obj's virtual function table in Rust
and provide our own implementations:
use c_char;
use ;
// VPtr implements Default for types that implement the trait, and provides
// a compile-time generated vtable!
// `RustObj` could then be passed to a C++ function that takes in a pointer to `Obj`.
// Single inheritance through a trait bound, is supported:.
// The vtable layout is fully typed and can be accessed as `<dyn TraitName as VmtLayout>::Layout<T>`.
// A `VPtr` can be `Deref`'d into it to obtain the bare function pointers and thus call through
// the vtable directly:
let obj = default;
let method_impl = obj.vftable.method; // extern "C" fn(&RustObj, u32) -> u32
let call_result = method_impl;