abi-vtable-macro
#[abi_vtable] — annotate a Rust trait and get the complete C contract for
dyn-loader's abi mode:
a #[repr(C)] vtable struct, one extern "C" thunk per method, a static
vtable instance and a #[no_mangle] getter — all generated.
use abi_vtable;
;
// One line: static instance + thunks + vtable + getter.
abi_vtable_impl_calc!;
The host (Rust, C, C++, Zig, ...) loads calc_get_vtable and calls through
the struct of function pointers — see dyn-loader's AbiTable.
Rules
- Field order of the generated vtable is the protocol: it follows trait method declaration order. Never reorder after release.
- All fn pointers are
extern "C"(cdecl), ctx-leading (*mut c_voidfirst). $instancemust be const-constructible (unit struct,const fn, literal).
License
MIT