#[repr(C)]pub struct FfiBuffer {
pub data: *mut u8,
pub len: usize,
pub capacity: usize,
}Expand description
FFI-safe byte buffer with explicit ownership semantics.
data points to a heap allocation of capacity bytes managed by
Rust’s global allocator. len is the number of initialized bytes.
§Safety
- This type does not implement
Drop. Callers must callffi_buffer_freeto release the memory. - Do not copy this struct without transferring ownership—double-free will result.
Fields§
§data: *mut u8§len: usize§capacity: usizeImplementations§
Source§impl FfiBuffer
impl FfiBuffer
Sourcepub fn null() -> Self
pub fn null() -> Self
Returns an FfiBuffer with all fields zero (null data pointer).
Represents an empty / absent buffer. Safe to pass to ffi_buffer_free.
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Allocate a new buffer of capacity bytes.
Returns FfiBuffer::null if capacity == 0.
§Panics
Panics if the allocator returns a null pointer (OOM).
Sourcepub fn from_vec(vec: Vec<u8>) -> Self
pub fn from_vec(vec: Vec<u8>) -> Self
Consume a Vec<u8> and wrap it as an FfiBuffer.
std::mem::forget is used to prevent Vec from running its destructor;
the caller must call ffi_buffer_free when done.
Sourcepub fn from_json<T: Serialize>(value: &T) -> Result<Self, FfiError>
pub fn from_json<T: Serialize>(value: &T) -> Result<Self, FfiError>
Serialize value to JSON and store it in a new FfiBuffer.
Sourcepub unsafe fn as_slice(&self) -> &[u8] ⓘ
pub unsafe fn as_slice(&self) -> &[u8] ⓘ
Return the initialized bytes as a slice.
§Safety
The caller must ensure self.data is valid for self.len bytes and
that no concurrent write is occurring.