WindfallProphet
WindfallProphet•4h ago

Accessing structs via FFI

Hi, I am trying to do some FFI. On the Rust side I have this struct
#[repr(C)]
pub struct LoginResult<T>
where
T: Default,
{
pub item: T, // null if none
pub code: u32, // 0 = ok, nonzero = error
}
#[repr(C)]
pub struct LoginResult<T>
where
T: Default,
{
pub item: T, // null if none
pub code: u32, // 0 = ok, nonzero = error
}
This is represented Deno side like so
login: {
parameters: ["buffer", "buffer"],
result: { "struct": [{ "struct": ["u32", "buffer", "i32"] }, "u32"] },
},
login: {
parameters: ["buffer", "buffer"],
result: { "struct": [{ "struct": ["u32", "buffer", "i32"] }, "u32"] },
},
The login function works, but I am not sure how to safely access the struct data.
1 Reply
Mrcool 🇵🇸
You can't use a generic in a struct you want to share in ffi different types will give different memory layout

Did you find this page helpful?