Skip to main content

FfiBuffer

Struct FfiBuffer 

Source
#[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_buffer to 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 u8

Pointer to the data

§len: usize

Length of valid data in bytes

§capacity: usize

Total capacity of the allocation

§error_code: u32

Error code (0 = success)

Implementations§

Source§

impl FfiBuffer

Source

pub fn empty() -> FfiBuffer

Create an empty buffer

Source

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.

Source

pub fn error(code: u32, message: &str) -> FfiBuffer

Create an error buffer

The error message is stored in the buffer data.

Source

pub fn success_json<T>(value: &T) -> FfiBuffer
where T: Serialize,

Create a success buffer with JSON data

Source

pub fn is_error(&self) -> bool

Check if this buffer represents an error

Source

pub fn is_empty(&self) -> bool

Check if this buffer is empty

Source

pub unsafe fn as_slice(&self) -> &[u8]

Get the data as a slice (unsafe - caller must ensure buffer is valid)

§Safety

The buffer must contain valid data and not have been freed.

Source

pub unsafe fn free(&mut self)

Free the buffer’s memory

§Safety

This must only be called once per buffer. After calling, the buffer is invalid and must not be used.

Trait Implementations§

Source§

impl Default for FfiBuffer

Source§

fn default() -> FfiBuffer

Returns the “default value” for a type. Read more
Source§

impl Send for FfiBuffer

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more