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>
impl<T: 'static> FfiLocalInitData<T>
Sourcepub unsafe fn set(info: duckdb_init_info, data: T)where
T: Send,
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
infomust be a validduckdb_init_infopassed to the table function’slocal_initcallback, not its globalinit. Both kinds of init data are stored throughduckdb_init_set_init_data, so the callback alone decides which one this sets; called frominit, it sets the global init data, whichFfiInitData::getwould then read as its own type.- Must be called at most once per
local_initinvocation.
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 per-thread local init data.
Returns None if no local init data was set.
§Safety
infomust be a validduckdb_function_info.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 per-thread local init data.
Returns None if no local init data was set.
§Safety
infomust be a validduckdb_function_info.Tmust be the type passed toset.- No other 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 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.