I am wrapping a C library that has two structures: one has a pointer to the other.
struct StructA {
void * some_mem;
};
struct StructB {
void * some_mem;
struct StructA * some_struct;
};
Both of these structures have their own memory, so my shell has constructors and destructors for both.
struct StructA(*mut c_void);
impl StructA {
fn new() -> Self {
StructA(c_constructor())
}
}
impl Drop for StructA {
fn drop(&mut self) {
let StructA(ptr) = self;
c_destructor(ptr);
}
}
There is also a function that takes a pointer to StructBand returns a pointer to StructA:
const struct StructA * get_struct(const struct StructB * obj);
The user of this function should not release the returned pointer, since it will be released when the user releases obj.
? , StructB , StructA. , get_struct , StructA (?). , ?
StructA , , , , .