#class #cpp #macro #struct #debugging #nothing #structures

macro cpp-inherit

Macros for enabling you to subclass a Rust struct from a C++ class

2 releases

0.1.1 Jul 31, 2020
0.1.0 Jul 31, 2020

#1468 in Procedural macros

MIT license

23KB
522 lines

cpp-inherit

A macro for inheriting Rust structures from C++ classes. Nothing of value lies here.

Example

use cpp_inherit::*;

#[inherit_from(BaseType)]
#[derive(Debug)]
struct RustType {}

#[inherit_from_impl(BaseType, "test.hpp")]
impl RustType {
    fn new() -> Self {
        Self {
            _base: BaseType { vtable_: RustType::VTABLE_ as _, value: 3 }
        }
    }

    #[overridden] fn x(&self) -> i32 {
        99
    }
}

// Now you can pass RustType as a BaseType, access any BaseType fields, call any BaseType methods (virtual or not), from either C++ or Rust

Rest of example usage here

Dependencies

~5MB
~107K SLoC