cxx
cxx copied to clipboard
Calling a non const C++ class member function from Rust
I am trying to call a non const C++ member function from rust but I am getting an error. Is it possible to call non const member function from Rust?
class MyClass { // The class public: // Access specifier int myNum; // Attribute (int variable) string myString; // Attribute (string variable) void function(weak_ptr<MyClass>) const; void function2() const; // I am able to call void function3(); // Not able to call this function ~MyClass(); };
Rust
#[cxx::bridge] mod ffi { unsafe extern "C++" { include!("demo/src/sample.h"); type MyClass; fn new_MyClass() -> UniquePtr<MyClass>; fn function(&self,a:WeakPtr<MyClass>) ; fn function2(&self); fn function3( &self ); } }
fn main() { println!("Hello, world!"); let mut ob = ffi::new_MyClass(); ob.function2(); ob.as_mut().function3();
}
Please put the code between ```cpp
and ```
as well as ```rust
and ```
!
See https://github.com/dtolnay/cxx/issues/1083#issuecomment-1222542362