pub unsafe fn init_extension<F>(
info: duckdb_extension_info,
access: *const duckdb_extension_access,
api_version: &str,
register: F,
) -> boolExpand description
Core entry point helper — sets up a connection and calls your registration closure.
This function encapsulates the correct initialization sequence for a DuckDB
loadable extension written in Rust:
- Calls
duckdb_rs_extension_api_initwith the givenapi_version. - Extracts the
duckdb_databaseviaaccess.get_database. - Opens a
duckdb_connectionviaduckdb_connect. - Calls
register(connection). - Disconnects with
duckdb_disconnect. - On any error, reports via
access.set_errorand returnsfalse.
The closure runs in one transaction, so a failed LOAD leaves no catalog
entry behind; casts, replacement scans and configuration options are not
rolled back. See the
module documentation.
§Return value
Returns true if initialization succeeded, false on any error.
§Safety
infomust be theduckdb_extension_infopassed byDuckDBto your entry point.accessmust be the*const duckdb_extension_accesspassed byDuckDB.- Both pointers must remain valid for the duration of this call.
§Pitfall L3: No panic across FFI
This function never panics. All errors are reported via access.set_error
(when access itself is null, there is nowhere to report one, and the
function returns false).
§Example
use quack_rs::entry_point::init_extension;
#[unsafe(no_mangle)]
pub unsafe extern "C" fn my_ext_init_c_api(
info: libduckdb_sys::duckdb_extension_info,
access: *const libduckdb_sys::duckdb_extension_access,
) -> bool {
unsafe {
init_extension(info, access, quack_rs::DUCKDB_API_VERSION, |_con| {
// Register your functions here
Ok(())
})
}
}