macro_rules! entry_point {
($fn_name:ident, $register:expr) => { ... };
($fn_name:ident, options = $options:expr, $register:expr) => { ... };
($fn_name:ident, $policy:expr, $register:expr) => { ... };
}Expand description
Generates the #[unsafe(no_mangle)] unsafe extern "C" entry point for a DuckDB extension.
This macro eliminates the boilerplate of writing the entry point manually.
It emits a #[unsafe(no_mangle)] pub unsafe extern "C" function with the name you
supply, which DuckDB locates by symbol when loading the extension.
§Arguments
$fn_name: The exact symbol nameDuckDBwill call (e.g.,my_extension_init_c_api).DuckDBrequires this to follow the{extension_name}_init_c_apiconvention.$register: A closure or function of typefn(duckdb_connection) -> Result<(), ExtensionError>that registers your functions on the given connection.
§ABI policy and options
A three-argument form takes an AbiPolicy between the name and the
closure, and options = an EntryPointOptions sets the policy and the
Registration mode together:
use quack_rs::abi::AbiPolicy;
use quack_rs::entry_point::{EntryPointOptions, Registration};
use quack_rs::error::ExtensionError;
quack_rs::entry_point!(my_ext_init_c_api, AbiPolicy::Trust, |_con| {
Ok::<(), ExtensionError>(())
});
quack_rs::entry_point!(
my_other_ext_init_c_api,
options = EntryPointOptions::new().registration(Registration::Autocommit),
|_con| Ok::<(), ExtensionError>(())
);The default is AbiPolicy::Strict, which
refuses to load when the running DuckDB does not provide the C API struct
layout this extension was compiled against. See crate::abi.
§panic = "abort"
The macro fails to compile when the extension is built with
panic = "abort", under which none of quack-rs’s panic guards work. See the
module documentation.
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.
§Example
use quack_rs::entry_point;
use quack_rs::error::ExtensionError;
fn register_functions(
_con: libduckdb_sys::duckdb_connection,
) -> Result<(), ExtensionError> {
Ok(())
}
entry_point!(my_extension_init_c_api, |con| register_functions(con));