#[repr(C)]pub struct FfiBuffer {
pub data: *mut u8,
pub len: usize,
pub capacity: usize,
pub error_code: u32,
}Expand description
Buffer for passing data across FFI boundary
This structure follows the “Rust allocates, host frees” pattern:
- Rust creates the buffer and populates it with data
- Host copies the data to its managed heap
- Host calls
plugin_free_bufferto release the memory
§Memory Safety
The buffer owns its memory. When plugin_free_buffer is called, the
memory is deallocated. The host must not use the buffer after freeing it.
Fields§
§data: *mut u8Pointer to the data
len: usizeLength of valid data in bytes
capacity: usizeTotal capacity of the allocation
error_code: u32Error code (0 = success)
Implementations§
Source§impl FfiBuffer
impl FfiBuffer
Sourcepub fn from_vec(vec: Vec<u8>) -> FfiBuffer
pub fn from_vec(vec: Vec<u8>) -> FfiBuffer
Create a buffer from a Vec
This transfers ownership of the Vec’s memory to the buffer.
Sourcepub fn error(code: u32, message: &str) -> FfiBuffer
pub fn error(code: u32, message: &str) -> FfiBuffer
Create an error buffer
The error message is stored in the buffer data.
Sourcepub fn success_json<T>(value: &T) -> FfiBufferwhere
T: Serialize,
pub fn success_json<T>(value: &T) -> FfiBufferwhere
T: Serialize,
Create a success buffer with JSON data
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FfiBuffer
impl RefUnwindSafe for FfiBuffer
impl !Sync for FfiBuffer
impl Unpin for FfiBuffer
impl UnsafeUnpin for FfiBuffer
impl UnwindSafe for FfiBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more