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>
impl<T: 'static> FfiInitData<T>
Sourcepub unsafe fn set(info: duckdb_init_info, data: T)
pub unsafe fn set(info: duckdb_init_info, data: T)
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
infomust be a validduckdb_init_infopassed to the table function’s globalinitcallback, not itslocal_init. Both kinds of init data are stored throughduckdb_init_set_init_data, so the callback alone decides which one this sets; called fromlocal_init, it sets the local init data, whichFfiLocalInitData::getwould then read as its own type.- Must be called at most once per init invocation.
Sourcepub unsafe fn get<'a>(info: duckdb_function_info) -> Option<&'a T>
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
infomust be a validduckdb_function_infofrom a scan callback.Tmust be the type passed toset.- No mutable reference to the same data must exist simultaneously.
- The returned reference must not outlive the scan callback:
DuckDBdestroys the data with the scan state.
Sourcepub unsafe fn get_mut<'a>(info: duckdb_function_info) -> Option<&'a mut T>
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
infomust be a validduckdb_function_infofrom a scan callback.Tmust be the type passed toset.- The returned reference must not outlive the scan callback:
DuckDBdestroys 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_threadsat 1 (the default) or the scan otherwise serialises calls toget_mut. WithInitInfo::set_max_threadsabove 1, usegetand interior mutability (Mutex, atomics) instead —local_initdoes not change this.
Sourcepub unsafe extern "C" fn destroy(ptr: *mut c_void)
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.