Expand description
Safe Rust binding for local Antfly databases and database-free inference
through the embedded libantfly C ABI.
This crate mirrors the reference Go binding (go/pkg/embedded) idiomatically:
Database is a Send + Sync handle safe for concurrent use from any
thread (libantfly’s only threading mode is “serialized” – see
threading_mode and zig/CAPI.md’s “Thread Safety” section). Every
fallible call returns a stable Error carrying the C ABI error code.
Most operations are exposed as *_json methods that take impl AsRef<[u8]> request bytes and return raw Vec<u8> response bytes,
matching the wire-level JSON contract shared with the Antfly server API
and the other language bindings. With the default-on serde feature,
typed convenience wrappers (Status, Capabilities, CheckReport,
…) are layered on top and re-exported here (see Status and
CheckReport, for example).
Calling into the real libantfly library requires the libantfly
Cargo feature (see antfly-embedded-sys’s docs); without it this crate still
builds (as an rlib) and its pure types (Error, OpenOptions, …) are
fully usable.
Modules§
- cypher
- inference_
mode - Inference execution mode strings returned by Lite status and
capabilities documents. Kept as
&'static strconstants (not an enum) because the C ABI defines them as stable strings, not a closed set of integers. - sql
- SQLSTATE-preserving SQL, session, and pull-cursor operations.
Structs§
- Capabilities
- Describes the Lite feature contract advertised by a handle.
- Check
Report - The typed form of
Database::check_json/crate::files::check_file_json. - Compact
Report - The typed form of
Database::compact_json. - Database
- An embedded Antfly database handle.
- Inference
- An embedded inference runtime handle, with no database. Models load on first use and stay cached until the handle closes.
- Inference
Error - An
Errortogether with the JSON error body anInferenceJSON call left behind, when there was one. - Inference
Options - Configures
Inference::open. - Inference
Status - Reports the configured inference execution mode for a Lite handle. See
go/pkg/embedded/status.go’sInferenceStatusdoc comment for the budget field semantics (0 vs. “resolved” values). - Live
Byte Accounting - Logical payload attribution from an explicit integrity check.
- Live
Byte Category - Logical key/value payload, excluding physical headers.
- Memory
Admission Stats - Historical snapshot of the local runtime’s last denied memory admission.
- Open
Options - Configures
crate::Database::openandcrate::Database::create. - Pending
Work Status - Describes the stable Lite readiness fields for derived work. Nested
maintenance telemetry is kept as raw JSON (
serde_json::Value) because its shape is operational detail rather than a stable control-plane contract. - Pull
Progress - One report from an
Inference::pullprogress callback. Owned (copied out of the C ABI’s borrowed, callback-lifetime-only struct) so it can be used freely – stored, sent across threads, etc. – without carrying a lifetime tied to the callback invocation. - Replay
Generated Enrichments Result - Reports how many generated enrichment references were recreated from stored documents.
- Restore
Options - Configures
crate::restoreandcrate::restore_file. - Stable
Snapshot Report - The typed form of
Database::copy_stable_snapshot_json. - Status
- The typed form of
Database::status_json.statsis kept as raw JSON because its shape is broader than the stable Lite control fields bindings need for feature branching. - Storage
Status - Describes the physical Lite database file backing a handle.
- Table
- A document handle borrowing a table’s owning database.
- TtlCleanup
Options - Configures the optional Lite TTL cleanup runtime.
- Vacuum
Report - The typed form of
Database::vacuum_json. - Write
Intent - A single key/value write or delete in a Lite batch.
Enums§
- Error
- A stable Antfly C ABI error code, mapped onto a typed Rust enum.
- Graph
Direction - Direction for
crate::Database::edges_jsonandcrate::Database::neighbors_json. - Open
Mode - Controls how an Antfly Lite file is opened.
- Outcome
Receipt Status - The resolved outcome of a write that failed with
Error::OutcomeUnknown; seeDatabase::outcome_receipt_status. - Profile
- Selects the Lite runtime profile.
- Storage
- Selects how a database is stored. The default is a single-file
.aflitedatabase. - TxnStatus
- A transaction intent lifecycle state.
- Typed
Error - Either an FFI error or a JSON decode failure from a typed convenience
method. The raw
*_jsonmethods onDatabasenever produce this; they returncrate::Result.
Constants§
- MIN_
THREAD_ STACK_ SIZE - Minimum stack, in bytes, for any thread that calls into a
Database. Rust’s default for spawned threads is 2 MiB, which is not enough; spawn callers withstd::thread::Builder::new().stack_size(MIN_THREAD_STACK_SIZE)(and size async runtimes’ blocking pools the same way). - SUPPORTED_
ABI_ VERSION - The Antfly C ABI version this binding expects.
- THREADING_
SERIALIZED - The only threading mode libantfly provides: any thread may call any
method on a
Databaseconcurrently. Seethreading_mode.
Functions§
- abi_
version - Returns the loaded Antfly C ABI version.
- check_
file - Runs Lite integrity checks for
pathwithout opening a database handle and returns the typed result. - check_
file_ json - Runs Lite integrity checks for
pathwithout opening a database handle and returns the JSON result. - copy_
stable_ snapshot_ file - Opens
src_pathread-only, copies a stable physical.aflitesnapshot todest_path, and returns the typed snapshot report. Both paths must end in.aflite. - copy_
stable_ snapshot_ file_ json - Opens
src_pathread-only, copies a stable Lite snapshot todest_path, and returns the JSON result. Neither path is required to end in.aflite; seecrate::maintenance::copy_stable_snapshot_filefor the suffix-checked, typed convenience. - decode_
artifact_ id_ json - Decodes a base64 artifact ID without opening a database.
- inference_
options_ size - Returns the loaded C ABI size of
antfly_inference_options. - open_
options_ size - Returns the loaded C ABI size of
antfly_open_options. - restore
- Creates a database at
pathfrom a portable Antfly backup archive, of the storage kindopts.storageselects. A backup of either kind restores into either kind.pathmust end in.aflitewhenopts.storageisStorage::Liteandbackupmust be non-empty.Error::OutcomeUnknownmeans the destination was published but crash durability could not be confirmed; inspect it and do not retry automatically. - restore_
file restorereading the archive frombackup_path(which must end in.afb). For.aflitedestinations it streams with bounded memory use.Error::Busymeans the source changed during streaming or the source/destination is concurrently locked; retry after the files are stable and no writer is active.Error::Unsupportedmeans the source filesystem lacks required advisory locking; copy the archive to a supported local filesystem.Error::OutcomeUnknownmeans the destination was published but crash durability could not be confirmed; inspect it and do not retry automatically.- threading_
mode - Reports the loaded libantfly threading contract, like
sqlite3_threadsafe(). - validate_
abi - Verifies that the loaded C library matches the header this binding was
compiled against. Every open function calls this first, like the Go
binding. A mismatch is reported as
Error::Internal: it indicates a build/deployment inconsistency (alibantflybuilt for a different ABI generation), not a normal operational failure.
Type Aliases§
- Inference
Result - A
Resultwhose error isInferenceError, returned byInference’s JSON call methods (as opposed tocrate::Result, used byInference::open/Inference::close, which do not produce a JSON body to report). - Result
- A
Resultwhose error type isError. - TxnId
- The stable 16-byte transaction identifier used by the C ABI.
- Typed
Result - A
Resultwhose error isTypedError, used by the typed convenience methods (as opposed tocrate::Result, used by the raw*_jsonmethods).