Skip to content

How to check that Rust type size is equal to C++ type size. #1373

@noy1993

Description

@noy1993

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;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions