A Rust struct
is mapped to a C++ class
/struct
with the same fields. If any field cannot be represented in C++, the struct itself will still have bindings, but the relevant field will be private.
To receive C++ bindings, the struct
must be movable in C++. See Movable Types.
Given the following Rust module:
cs/file:examples/rust/struct/example.rs class:Struct
Crubit will generate the following bindings:
cs/file:examples/rust/struct/example_generated.h class:CRUBIT_INTERNAL_RUST_TYPE|Struct
The fields on the C++ class are the corresponding Rust types:
Fields that do not receive bindings are made private, and replaced with an opaque blob of maybe-uninitialized bytes, as well as a comment in the generated source code explaining why the field could not receive bindings. For example, since String
is not supported, the space of the object occupied by a String
field will instead be this opaque blob of bytes:
// Rust: `my_field` is some unsupported type, such as `String` pub my_field: String,
// C++: `my_field` becomes `private`, and its type is replaced by bytes. private: unsigned char my_field[24]
Specifically, the following subobjects are hidden and replaced with opaque blobs:
private
or pub(...)
fields).Drop
.To receive C++ bindings, the struct
must be movable in C++. See Movable Types.