Skip to main content

Crate antfly_embedded

Crate antfly_embedded 

Source
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 str constants (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.
CheckReport
The typed form of Database::check_json / crate::files::check_file_json.
CompactReport
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.
InferenceError
An Error together with the JSON error body an Inference JSON call left behind, when there was one.
InferenceOptions
Configures Inference::open.
InferenceStatus
Reports the configured inference execution mode for a Lite handle. See go/pkg/embedded/status.go’s InferenceStatus doc comment for the budget field semantics (0 vs. “resolved” values).
LiveByteAccounting
Logical payload attribution from an explicit integrity check.
LiveByteCategory
Logical key/value payload, excluding physical headers.
MemoryAdmissionStats
Historical snapshot of the local runtime’s last denied memory admission.
OpenOptions
Configures crate::Database::open and crate::Database::create.
PendingWorkStatus
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.
PullProgress
One report from an Inference::pull progress 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.
ReplayGeneratedEnrichmentsResult
Reports how many generated enrichment references were recreated from stored documents.
RestoreOptions
Configures crate::restore and crate::restore_file.
StableSnapshotReport
The typed form of Database::copy_stable_snapshot_json.
Status
The typed form of Database::status_json. stats is kept as raw JSON because its shape is broader than the stable Lite control fields bindings need for feature branching.
StorageStatus
Describes the physical Lite database file backing a handle.
Table
A document handle borrowing a table’s owning database.
TtlCleanupOptions
Configures the optional Lite TTL cleanup runtime.
VacuumReport
The typed form of Database::vacuum_json.
WriteIntent
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.
GraphDirection
Direction for crate::Database::edges_json and crate::Database::neighbors_json.
OpenMode
Controls how an Antfly Lite file is opened.
OutcomeReceiptStatus
The resolved outcome of a write that failed with Error::OutcomeUnknown; see Database::outcome_receipt_status.
Profile
Selects the Lite runtime profile.
Storage
Selects how a database is stored. The default is a single-file .aflite database.
TxnStatus
A transaction intent lifecycle state.
TypedError
Either an FFI error or a JSON decode failure from a typed convenience method. The raw *_json methods on Database never produce this; they return crate::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 with std::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 Database concurrently. See threading_mode.

Functions§

abi_version
Returns the loaded Antfly C ABI version.
check_file
Runs Lite integrity checks for path without opening a database handle and returns the typed result.
check_file_json
Runs Lite integrity checks for path without opening a database handle and returns the JSON result.
copy_stable_snapshot_file
Opens src_path read-only, copies a stable physical .aflite snapshot to dest_path, and returns the typed snapshot report. Both paths must end in .aflite.
copy_stable_snapshot_file_json
Opens src_path read-only, copies a stable Lite snapshot to dest_path, and returns the JSON result. Neither path is required to end in .aflite; see crate::maintenance::copy_stable_snapshot_file for 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 path from a portable Antfly backup archive, of the storage kind opts.storage selects. A backup of either kind restores into either kind. path must end in .aflite when opts.storage is Storage::Lite and backup must be non-empty. Error::OutcomeUnknown means the destination was published but crash durability could not be confirmed; inspect it and do not retry automatically.
restore_file
restore reading the archive from backup_path (which must end in .afb). For .aflite destinations it streams with bounded memory use. Error::Busy means the source changed during streaming or the source/destination is concurrently locked; retry after the files are stable and no writer is active. Error::Unsupported means the source filesystem lacks required advisory locking; copy the archive to a supported local filesystem. Error::OutcomeUnknown means 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 (a libantfly built for a different ABI generation), not a normal operational failure.

Type Aliases§

InferenceResult
A Result whose error is InferenceError, returned by Inference’s JSON call methods (as opposed to crate::Result, used by Inference::open/Inference::close, which do not produce a JSON body to report).
Result
A Result whose error type is Error.
TxnId
The stable 16-byte transaction identifier used by the C ABI.
TypedResult
A Result whose error is TypedError, used by the typed convenience methods (as opposed to crate::Result, used by the raw *_json methods).