Bitfield and Union for low level data structures and type conversion in rust

You could pass that C struct to Rust as an opaque pointer and expose a C API to work with that pointer that the Rust code would call. So C would own that memory and layout, and Rust just sees a pointer with a bunch of functions that can operate on it.

Personally, I’d just stick to C if this case comes up very often :slight_smile:. If, however, this is a minor part of the overall code and the rest can be done in safe Rust, then it’s a reasonable alternative.

1 Like