You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A common pattern is to declare structs/classes in a header, but leave their definition incomplete so that the public API consumers can't manipulate them directly and can only pass pointers/references to API functions that do the heavy lifting. Additionally, API consumers can't construct instances of these incomplete types, and rely on getting pointers to them from other public API functions.
The way we generate a struct for MyDetailsArePrivate means that Rust users can construct instances. This is incorrect, and the false instances are almost assuredly the wrong size, and definitely will contain invalid data. This means that passing pointers to them into FFI functions would be wildly unsafe.
If instead we generated an enum without any variants, then it would be impossible to construct false instances in Rust, but the FFI functions that take and receive pointers to it would continue to work:
A common pattern is to declare structs/classes in a header, but leave their definition incomplete so that the public API consumers can't manipulate them directly and can only pass pointers/references to API functions that do the heavy lifting. Additionally, API consumers can't construct instances of these incomplete types, and rely on getting pointers to them from other public API functions.
Simple example:
We currently generate Rust bindings like this (trimmed down for brevity):
The way we generate a struct for
MyDetailsArePrivate
means that Rust users can construct instances. This is incorrect, and the false instances are almost assuredly the wrong size, and definitely will contain invalid data. This means that passing pointers to them into FFI functions would be wildly unsafe.If instead we generated an
enum
without any variants, then it would be impossible to construct false instances in Rust, but the FFI functions that take and receive pointers to it would continue to work:The text was updated successfully, but these errors were encountered: