sqlite_loadable/
entrypoints.rs

1//! Utilities for working with SQLite's "sqlite3_extension_init"-style
2//! entrypoints.
3use crate::{errors::Result, ext::faux_sqlite_extension_init2};
4
5use sqlite3ext_sys::{sqlite3, sqlite3_api_routines, SQLITE_OK};
6
7use std::os::raw::{c_char, c_uint};
8
9/// Low-level wrapper around a typical entrypoint to a SQLite extension.
10/// You shouldn't have to use this directly - the sqlite_entrypoint
11/// macro will do this for you.
12pub fn register_entrypoint<F>(
13    db: *mut sqlite3,
14    _pz_err_msg: *mut *mut c_char,
15    p_api: *mut sqlite3_api_routines,
16    callback: F,
17) -> c_uint
18where
19    F: Fn(*mut sqlite3) -> Result<()>,
20{
21    unsafe {
22        faux_sqlite_extension_init2(p_api);
23    }
24    match callback(db) {
25        Ok(()) => SQLITE_OK,
26        Err(err) => err.code_extended(),
27    }
28}