Cxx, rust-bindgen


By any chance, is there 'prior art' on converting C/C++ type definitions into Rust native data structures?
I know there's cxx and bindgen for calling into C/C++, from Rust, but anything that converts the definitions to native Rust?

Asking on the heels of 1password releasing 'TypeShare' for re-using Rust types in Kotlin, Swift, Typescript, Go.

Is using syn the only way... to parse C header files, for example, and add logic to convert to native rust types?

Besides providing unsafe extern "C" function declarations, the bindgen crate will define ABI-compatible Rust types for your C/C++ types.

Rust has enough control over how types are laid out in memory that there is no "conversion" logic required for interoperating with C or (most basic) C++ - you can just do a pointer cast.

Thanks, there's no interop required at all. Just looking to convert headers to Rust data types.
So, changing from unions in .h to Rust enums, for example...

That's fine. You can just take the types generated by bindgen and ignore the functions.

Okay, thank you, I'll explore.