Attribute Macro autocxx::subclass::subclass

source ·
#[subclass]
Expand description

Declare a Rust subclass of a C++ class. You can use this in two ways:

  • As an attribute macro on a struct which is to be a subclass. In this case, you must specify the superclass as described below. For instance,
    # use autocxx_macro::subclass as subclass;
    #[subclass(superclass("MyCppSuperclass"))]
    struct Bar {};
    
  • as a directive within the crate::include_cpp macro, in which case you must provide two arguments of the superclass and then the subclass:
    include_cpp!(
        #include "input.h"
        subclass!("MyCppSuperclass",Bar)
        safety!(unsafe)
    );
    struct Bar {
      // ...
    }
    In this latter case, you’ll need to implement the trait CppSubclass for the struct, so it’s generally easier to use the former option.

See CppSubclass for information about the multiple steps you need to take to be able to make Rust subclasses of a C++ class. Attribute to state that a Rust struct is a C++ subclass. This adds an additional field to the struct which autocxx uses to track a C++ instantiation of this Rust subclass.