Reputation: 9410
I have some c functions with a struct pointer argument.
extern "C" {
fn InitSomeStruct() -> *SomeStruct;
fn SomeFunction(v: *SomeStruct);
fn DestroySomeStruct(v: *SomeStruct);
}
fn main() {
unsafe {
let s = InitSomeStruct();
SomeFunction(s);
DestroySomeStruct(s);
}
}
The implementation of SomeStruct is unknown. How to declare and use external struct like SomeStruct from the rust code?
Upvotes: 0
Views: 735
Reputation: 102066
The convention is to use an empty enum for opaque FFI types, that is:
enum SomeStruct {}
An empty struct like struct SomeStruct;
is also used sometimes.
Upvotes: 2