cxx
cxx copied to clipboard
How to check that Rust type size is equal to C++ type size.
I have a question: If the size of types in C++ and Rust are different, the code might still compile, but it would be very unsafe. Is there a way to make the compiler throw an error when the sizes of C++ and Rust types do not match?
For example, with the following code, a Rust Foo struct could be directly transmuted into a C++ Foo.
rust code:
struct Foo{
v:f64
v2:f64
}
unsafe impl ExternType for Foo {
type Id = cxx::type_id!("Foo");
type Kind = cxx::kind::Trivial;
}
c++ code:
class Foo{
public:
double v;
};