Skip to main content

limbo_ext/
lib.rs

1// UPSTREAM: vendored Limbo fork — allow upstream style
2//! Extension API for the C-free **oxisqlite** engine: write new SQL
3//! functionality in pure Rust, no C, in the spirit of `sqlite3` extensions.
4//!
5//! Provides the `scalar`, `AggregateDerive`, and `VTabModuleDerive` macros
6//! (scalar/aggregate functions, virtual tables), an optional `vfs`-gated VFS
7//! interface, and the `register_extension!` macro that plugs it all in.
8#![allow(
9    rustdoc::bare_urls,
10    rustdoc::invalid_html_tags,
11    rustdoc::invalid_rust_codeblocks
12)]
13#![allow(clippy::cast_slice_from_raw_parts)]
14
15mod functions;
16mod types;
17#[cfg(feature = "vfs")]
18mod vfs_modules;
19mod vtabs;
20pub use functions::{
21    AggCtx, AggFunc, FinalizeFunction, InitAggFunction, ScalarFunction, StepFunction,
22};
23use functions::{RegisterAggFn, RegisterScalarFn};
24#[cfg(feature = "vfs")]
25pub use limbo_macros::VfsDerive;
26pub use limbo_macros::{register_extension, scalar, AggregateDerive, VTabModuleDerive};
27use std::os::raw::c_void;
28pub use types::{ResultCode, StepResult, Value, ValueType};
29#[cfg(feature = "vfs")]
30pub use vfs_modules::{RegisterVfsFn, VfsExtension, VfsFile, VfsFileImpl, VfsImpl, VfsInterface};
31use vtabs::RegisterModuleFn;
32pub use vtabs::{
33    Conn, Connection, ConstraintInfo, ConstraintOp, ConstraintUsage, ExtIndexInfo, IndexInfo,
34    OrderByInfo, Statement, Stmt, VTabCreateResult, VTabCursor, VTabKind, VTabModule,
35    VTabModuleImpl, VTable,
36};
37
38pub type ExtResult<T> = std::result::Result<T, ResultCode>;
39
40pub type ExtensionEntryPoint = unsafe extern "C" fn(api: *const ExtensionApi) -> ResultCode;
41
42#[repr(C)]
43pub struct ExtensionApi {
44    pub ctx: *mut c_void,
45    pub register_scalar_function: RegisterScalarFn,
46    pub register_aggregate_function: RegisterAggFn,
47    pub register_vtab_module: RegisterModuleFn,
48    #[cfg(feature = "vfs")]
49    pub vfs_interface: VfsInterface,
50}
51
52unsafe impl Send for ExtensionApi {}
53unsafe impl Send for ExtensionApiRef {}
54
55#[repr(C)]
56pub struct ExtensionApiRef {
57    pub api: *const ExtensionApi,
58}