lib.rs

Overview

This file provides low-level bindings and utility functions for interfacing with the SQLite3 C API, particularly focusing on virtual table (vtab) support and SQLite's destructor behavior management. It defines safe Rust abstractions over certain SQLite constructs and manages linking with OpenSSL when a specific feature flag is enabled. The file exposes necessary types and constants for use in other parts of the system that interact with SQLite3.

Modules and Imports

Public Functions

SQLITE_STATIC() -> sqlite3_destructor_type

Returns the SQLite "static" destructor type, represented as None. This signifies to SQLite that the data pointer passed to it is static and does not require SQLite to free or manage it.

Example Usage:

let destructor = SQLITE_STATIC();
// Use `destructor` as the callback when binding a static buffer in SQLite.

SQLITE_TRANSIENT() -> sqlite3_destructor_type

Returns the SQLite "transient" destructor type. It uses an unsafe transmute to cast -1_isize into a destructor callback pointer. This value tells SQLite to make its own private copy of the data because the data will not be valid after the call returns.

Example Usage:

let destructor = SQLITE_TRANSIENT();
// Use `destructor` when binding buffers that Rust owns and may drop.

Traits Implemented

Default for sqlite3_vtab

Implements the Default trait for the sqlite3_vtab struct, which represents a virtual table in SQLite. The default instance is created by zero-initializing the memory for this struct using mem::zeroed(). This is necessary because sqlite3_vtab is a C struct and does not have safe default values.

Default for sqlite3_vtab_cursor

Similar to sqlite3_vtab, sqlite3_vtab_cursor represents a cursor for navigating virtual tables. This implementation provides a zeroed default instance.

Internal Modules

error

This module contains error types and related utilities for handling SQLite errors. It is re-exported at the top level for use throughout the system.

bindings

This module includes Rust definitions automatically generated from SQLite's C headers using bindgen. It exposes all SQLite C API types, functions, and constants. The bindings module is re-exported publicly for use by other parts of the system.

Interaction with Other System Components

Important Implementation Details

Diagram: Structure and Workflow of lib.rs

flowchart TD
A[lib.rs] --> B[error module]
A --> C[bindings module]
A --> D[SQLITE_STATIC function]
A --> E[SQLITE_TRANSIENT function]
A --> F[Default impl for sqlite3_vtab]
A --> G[Default impl for sqlite3_vtab_cursor]
subgraph bindings
C
end
subgraph error
B
end

This diagram illustrates the main components and their relationships within the file: the two internal modules error and bindings and the utility functions and trait implementations exposed at the top level.