Skip to main content

OwnedBytes

Struct OwnedBytes 

Source
#[repr(C)]
pub struct OwnedBytes { pub ptr: *mut u8, pub len: usize, pub cap: usize, pub drop_fn: Option<unsafe extern "C" fn(ptr: *mut u8, len: usize, cap: usize)>, }
Expand description

An owned byte buffer crossing the plug-in boundary.

Allocated by the producing side and freed by the producer’s drop_fn so allocator mismatches between host and plug-in stay impossible. v1 uses this only for runtime-constructed error messages; data payloads cross via other paths (Arrow IPC for batches, JSON via OwnedBytes for single items).

Fields§

§ptr: *mut u8§len: usize§cap: usize§drop_fn: Option<unsafe extern "C" fn(ptr: *mut u8, len: usize, cap: usize)>

Implementations§

Source§

impl OwnedBytes

Source

pub const fn empty() -> Self

Constructs an empty OwnedBytes with no drop function.

Source

pub fn is_empty(&self) -> bool

Returns whether the buffer is empty (no allocation).

Source

pub fn from_vec(v: Vec<u8>) -> Self

Constructs an OwnedBytes from a Rust Vec<u8> using the producer’s allocator and stamps the matching producer-side free as drop_fn.

Consumers release the buffer by dropping the OwnedBytes (which invokes the embedded drop_fn) or by calling that drop_fn explicitly. Do not call drop_owned_bytes on a value received across the plug-in boundary: that would free with the consumer’s allocator, which may not match the producer’s. drop_owned_bytes is only the default function installed here for the producer; each side sees its own copy linked against its own allocator.

Source

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

Borrows the buffer as a byte slice.

§Safety

The buffer must still be live (i.e. its drop_fn not yet called).

Trait Implementations§

Source§

impl Drop for OwnedBytes

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for OwnedBytes

SAFETY: a heap pointer freed only by its producer’s drop_fn; safe to transfer ownership across threads.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.