sqlite-vec/site/using/rust.md

34 lines
1,003 B
Markdown
Raw Normal View History

2024-06-11 23:58:00 -07:00
# Using `sqlite-vec` in Rust
2024-07-14 13:47:41 -07:00
You can embed `sqlite-vec` into your Rust projects using the official
[`sqlite-vec` crate](https://crates.io/crates/sqlite-vec).
2024-06-11 23:58:00 -07:00
```bash
cargo add sqlite-vec
```
2024-07-14 13:47:41 -07:00
The crate embeds the `sqlite-vec` C source code, and uses the
[`cc` crate](https://crates.io/crates/sqlite-vec) to compile and statically link
`sqlite-vec` at build-time.
The `sqlite-vec` crate exposes a single function `sqlite3_vec_init`, which is
the C entrypoint for the SQLite extension. You can "register" with your Rust
SQLite library's `sqlite3_auto_extension()` function. Here's an example with
`rusqlite`:
```rs
use sqlite_vec::sqlite3_vec_init;
use rusqlite::{ffi::sqlite3_auto_extension};
fn main() {
unsafe {
sqlite3_auto_extension(Some(std::mem::transmute(sqlite3_vec_init as *const ())));
}
// future database connection will now automatically include sqlite-vec functions!
}
```
A full [`sqlite-vec` Rust demo](#TODO) is also available.
2024-06-11 23:58:00 -07:00
## Working with vectors in Rust