cxx
cxx copied to clipboard
Implementing Rust method in C++ results in "not FFI-safe" error
I'm trying to expose a Rust defined type and implement one of its method in C++
#[cxx::bridge]
pub mod ffi {
extern "Rust" {
type Test;
}
unsafe extern "C++" {
fn bar(self: &Test);
}
}
struct Test {
foo: String,
}
Results in:
error: `extern` block uses type `Test`, which is not FFI-safe
--> lib.rs:36:22
|
36 | fn bar(self: &Test);
| ^^^^^ not FFI-safe
|
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
The generated C++ bindings are correct and can be successfully compiled.