uniffi-rs icon indicating copy to clipboard operation
uniffi-rs copied to clipboard

RustBuffer should be a data pointer

Open bendk opened this issue 2 years ago • 0 comments

RustBuffer is currently defined as:

pub struct RustBuffer {
    capacity: i32,
    len: i32,
    data: *mut u8,
}

I'd think this should change to just a *mut u8. We could write the capacity and len as the first 8 bytes to create an equivalent structure. Maybe we could drop one or both of these fields, the foreign FFI converter code can now calculate the size it needs so I'm not sure these are necessary anymore.

The reason for the change is that pointers are simpler to handle at the at the FFI layer than structs. I'm currently running into a 14 year-old ctypes issue that prevents us from returning RustBuffer from Python callbacks. I remember noticing that the structs were relatively slow on Kotlin when I was looking at callback interface performance. That's not a ton of data points, but my feeling is that making this switch will make things easier in general.

bendk avatar Oct 04 '23 18:10 bendk