Skip to main content

FfiInitData

Struct FfiInitData 

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

Type-safe global init data for DuckDB table functions.

Set in the global init callback; retrieved in scan.

Implementations§

Source§

impl<T: 'static> FfiInitData<T>

Source

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

Stores data as the global init data for this query.

Call inside your global init callback.

T must be Send + Sync: the value is created on the init thread, read by up to max_threads concurrent scan calls, and dropped on whichever thread tears the plan down.

§Safety
  • info must be a valid duckdb_init_info passed to the table function’s global init callback, not its local_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 local_init, it sets the local init data, which FfiLocalInitData::get would then read as its own type.
  • Must be called at most once per init invocation.
Source

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

Retrieves a shared reference to the global init data from a scan callback.

Returns None if no init data was set. Concurrent scan calls may hold this reference at the same time; set requires T: Sync for that reason.

§Safety
  • info must be a valid duckdb_function_info from a scan callback.
  • 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 global init data from a scan callback.

Returns None if no init data was set.

§Safety
  • info must be a valid duckdb_function_info from a scan callback.
  • T must be the type passed to set.
  • The returned reference must not outlive the scan callback: DuckDB destroys the data with the scan state.
  • No other reference to the same data must exist simultaneously. Global init data is shared by every concurrent scan call of the query, so this holds only when the init callback left max_threads at 1 (the default) or the scan otherwise serialises calls to get_mut. With InitInfo::set_max_threads above 1, use get and interior mutability (Mutex, atomics) instead — local_init does not change this.
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 FfiInitData<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 FfiInitData<T>

§

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

§

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

§

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

§

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

§

impl<T> UnsafeUnpin for FfiInitData<T>

§

impl<T> UnwindSafe for FfiInitData<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.