Skip to main content

dtlvnative_sys/
lib.rs

1//! Raw bindings generated from the pinned DLMDB, USearch, and DTLV llama headers.
2//!
3//! Every native call requires the caller to uphold the native ownership,
4//! transaction, threading, and buffer validity contracts. No stock LMDB library
5//! may be substituted for the versioned DLMDB native artifact.
6
7#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)]
8
9/// Native artifact source revision, configuration, version, and checksum.
10pub const BUILD_INFO: &str = include_str!(concat!(env!("OUT_DIR"), "/build-info.txt"));
11
12#[cfg(feature = "dlmdb")]
13mod bindings {
14    #![allow(clippy::all, clippy::undocumented_unsafe_blocks)]
15    include!(concat!(env!("OUT_DIR"), "/bindings-dlmdb.rs"));
16}
17
18#[cfg(feature = "dlmdb")]
19pub use bindings::*;
20
21#[cfg(any(feature = "usearch", feature = "llama"))]
22pub mod runtime;
23
24#[cfg(feature = "usearch")]
25pub mod usearch {
26    use std::sync::OnceLock;
27    mod bindings {
28        #![allow(clippy::all, clippy::undocumented_unsafe_blocks)]
29        include!(concat!(env!("OUT_DIR"), "/bindings-usearch.rs"));
30    }
31    pub use bindings::*;
32    static API: OnceLock<Result<UsearchApi, String>> = OnceLock::new();
33
34    /// Load every required symbol from the packaged runtime, once per process.
35    pub fn api() -> Result<&'static UsearchApi, &'static str> {
36        API.get_or_init(|| {
37            let library = super::runtime::load(env!("DTLVNATIVE_USEARCH_LIBRARY"))?;
38            // SAFETY: Bindings and runtime come from the same pinned headers and
39            // archive version. The generated API owns the loaded library.
40            unsafe { UsearchApi::from_library(library).map_err(|error| error.to_string()) }
41        })
42        .as_ref()
43        .map_err(String::as_str)
44    }
45}
46
47#[cfg(feature = "llama")]
48pub mod llama {
49    use std::sync::OnceLock;
50    mod bindings {
51        #![allow(clippy::all, clippy::undocumented_unsafe_blocks)]
52        include!(concat!(env!("OUT_DIR"), "/bindings-llama.rs"));
53    }
54    pub use bindings::*;
55    static API: OnceLock<Result<LlamaApi, String>> = OnceLock::new();
56
57    /// Load every required symbol from the packaged runtime, once per process.
58    pub fn api() -> Result<&'static LlamaApi, &'static str> {
59        API.get_or_init(|| {
60            let library = super::runtime::load(env!("DTLVNATIVE_LLAMA_LIBRARY"))?;
61            // SAFETY: Bindings and runtime come from the same pinned headers and
62            // archive version. The generated API owns the loaded library.
63            unsafe { LlamaApi::from_library(library).map_err(|error| error.to_string()) }
64        })
65        .as_ref()
66        .map_err(String::as_str)
67    }
68}