Skip to main content

FfiLocalInitData

Struct FfiLocalInitData 

Source
pub struct FfiLocalInitData<T: 'static> { /* private fields */ }
Expand description

Type-safe per-thread local init data for DuckDB table functions.

Set in the local_init callback; retrieved in scan.

Implementations§

Source§

impl<T: 'static> FfiLocalInitData<T>

Source

pub unsafe fn set(info: duckdb_init_info, data: T)
where T: Send,

Stores data as the per-thread local init data.

Call inside your local_init callback.

T must be Send: a scanning task may be resumed on a different worker thread, and the value is dropped wherever the plan is torn down.

§Safety
  • info must be a valid duckdb_init_info passed to the table function’s local_init callback, not its global init. Both kinds of init data are stored through duckdb_init_set_init_data, so the callback alone decides which one this sets; called from init, it sets the global init data, which FfiInitData::get would then read as its own type.
  • Must be called at most once per local_init invocation.
Source

pub unsafe fn get<'a>(info: duckdb_function_info) -> Option<&'a T>

Retrieves a shared reference to the per-thread local init data.

Returns None if no local init data was set.

§Safety
  • info must be a valid duckdb_function_info.
  • T must be the type passed to set.
  • No mutable reference to the same data must exist simultaneously.
  • The returned reference must not outlive the scan callback: DuckDB destroys the data with the scan state.
Source

pub unsafe fn get_mut<'a>(info: duckdb_function_info) -> Option<&'a mut T>

Retrieves a mutable reference to the per-thread local init data.

Returns None if no local init data was set.

§Safety
  • info must be a valid duckdb_function_info.
  • T must be the type passed to set.
  • No other reference to the same data must exist simultaneously.
  • The returned reference must not outlive the scan callback: DuckDB destroys the data with the scan state.
Source

pub unsafe extern "C" fn destroy(ptr: *mut c_void)

Destroy callback: drops the Box<T>.

§Pitfall L3: T::drop is user code

DuckDB calls this through an extern "C" function pointer that has no error channel, and an unwind across extern "C" aborts the process on Rust 1.81+. The drop runs under catch_ffi_panic so a panicking Drop impl cannot take the session down.

§Safety

ptr must have been allocated by set.

Trait Implementations§

Source§

impl<T: 'static> Debug for FfiLocalInitData<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for FfiLocalInitData<T>

§

impl<T> RefUnwindSafe for FfiLocalInitData<T>
where T: RefUnwindSafe,

§

impl<T> Send for FfiLocalInitData<T>
where T: Send,

§

impl<T> Sync for FfiLocalInitData<T>
where T: Sync,

§

impl<T> Unpin for FfiLocalInitData<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for FfiLocalInitData<T>

§

impl<T> UnwindSafe for FfiLocalInitData<T>
where T: UnwindSafe,

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, 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.