Skip to main content

antfly_embedded/
lib.rs

1// Copyright 2026 Antfly, Inc.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//     http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! Safe Rust binding for local Antfly databases and database-free inference
17//! through the embedded `libantfly` C ABI.
18//!
19//! This crate mirrors the reference Go binding (`go/pkg/embedded`) idiomatically:
20//! [`Database`] is a `Send + Sync` handle safe for concurrent use from any
21//! thread (libantfly's only threading mode is "serialized" -- see
22//! [`threading_mode`] and `zig/CAPI.md`'s "Thread Safety" section). Every
23//! fallible call returns a stable [`Error`] carrying the C ABI error code.
24//!
25//! Most operations are exposed as `*_json` methods that take `impl
26//! AsRef<[u8]>` request bytes and return raw `Vec<u8>` response bytes,
27//! matching the wire-level JSON contract shared with the Antfly server API
28//! and the other language bindings. With the default-on `serde` feature,
29//! typed convenience wrappers ([`Status`], [`Capabilities`], [`CheckReport`],
30//! ...) are layered on top and re-exported here (see [`Status`] and
31//! [`CheckReport`], for example).
32//!
33//! Calling into the real `libantfly` library requires the `libantfly`
34//! Cargo feature (see `antfly-embedded-sys`'s docs); without it this crate still
35//! builds (as an rlib) and its pure types (`Error`, `OpenOptions`, ...) are
36//! fully usable.
37
38mod db;
39mod error;
40mod ffi;
41mod files;
42mod inference;
43mod options;
44mod transactions;
45
46#[cfg(feature = "serde")]
47mod maintenance;
48#[cfg(feature = "serde")]
49mod status;
50
51pub use db::{
52    Database, MIN_THREAD_STACK_SIZE, OutcomeReceiptStatus, SUPPORTED_ABI_VERSION,
53    THREADING_SERIALIZED, Table, abi_version, decode_artifact_id_json, open_options_size,
54    threading_mode, validate_abi,
55};
56#[cfg(feature = "libantfly")]
57pub use error::last_error_detail;
58pub use error::{Error, Result};
59pub use files::{check_file_json, copy_stable_snapshot_file_json, restore, restore_file};
60pub use inference::{
61    Inference, InferenceError, InferenceOptions, InferenceResult, PullProgress,
62    inference_options_size,
63};
64pub use options::{
65    GraphDirection, OpenMode, OpenOptions, Profile, RestoreOptions, Storage, TtlCleanupOptions,
66    WriteIntent, inference_mode,
67};
68pub use transactions::{TxnId, TxnStatus};
69
70#[cfg(feature = "serde")]
71pub use maintenance::{
72    CheckReport, CompactReport, LiveByteAccounting, LiveByteCategory, StableSnapshotReport,
73    VacuumReport, check_file, copy_stable_snapshot_file,
74};
75#[cfg(feature = "serde")]
76pub use status::{
77    Capabilities, InferenceStatus, MemoryAdmissionStats, PendingWorkStatus,
78    ReplayGeneratedEnrichmentsResult, Status, StorageStatus, TypedError, TypedResult,
79};
80
81#[cfg(feature = "serde")]
82pub mod cypher;
83#[cfg(feature = "serde")]
84pub mod sql;
85#[cfg(feature = "sqlx")]
86pub mod sqlx;