use cpp_oop::gen_oop; gen_oop! { #[default] struct Foo { foo: u32, } struct FooLayout { #[virt] foo: fn(this: &Self, a: i32) -> u32, } impl FooMethodsInner for Foo { extern "C" fn foo_inner_virt(_this: &Self, _a: i32) -> u32 { 1 } } } #[test] fn layout() { assert_eq!(std::mem::size_of::(), std::mem::size_of::() * 2); } #[test] fn basic() { let f = Foo::default(); let f_ptr = &f as *const Foo; assert_eq!(Foo::foo_inner_virt(&f, 0), 1); // manual selection of the method to call assert_eq!(f.foo(0), 1); // static dispatch assert_eq!(f_ptr.foo(0), 1); // use vtable lookup }