Skip to main content

brain_db_sdk/
lib.rs

1//! brain-db-sdk — Rust client for the Brain memory database.
2//!
3//! Brain ships no client library; its contract is the wire protocol — a
4//! 32-byte `BRN0` frame header plus CBOR payloads over TCP. This crate
5//! re-implements that protocol independently (the protocol, not a shared
6//! library, is the source of truth) and is verified byte-for-byte
7//! against Brain's vendored conformance corpus.
8//!
9//! The [`wire`] module is the codec: the frame codec ([`wire::frame`]),
10//! the CBOR payload codec ([`wire::cbor`]), the opcode table
11//! ([`wire::opcode`]), and the typed payload structs ([`wire::types`]) for
12//! the handshake and the verbs — all runtime-agnostic and verified against
13//! the corpus.
14//!
15//! Layered on top: [`transport`] reads/writes whole frames over an async byte
16//! stream, [`mux`] is the multiplexed [`MuxConnection`] (a background reader
17//! task demultiplexes responses by `stream_id`) — the one connection type — and
18//! [`client`] is the high-level [`BrainClient`] built on it — every verb takes
19//! `&self`, so one client serves concurrent requests. [`verbs`] holds the
20//! ergonomic request builders, [`retry`] the backoff combinator, and [`pool`] a
21//! fixed-size connection pool for socket-level parallelism. Transparent
22//! reconnect and connection-pool health-checking are the remaining later work.
23
24pub mod client;
25pub mod error;
26pub mod http;
27pub mod mux;
28pub mod pool;
29pub mod retry;
30pub mod transport;
31pub mod verbs;
32pub mod wire;
33
34pub use client::{
35    derive_space_id, new_id, Auth, BrainClient, ClientConfig, ConnectionInfo, RecallAnswer,
36};
37pub use error::{BrainError, Result};
38pub use mux::{HandshakeOutcome, MuxConnection, Subscription};
39pub use pool::Pool;
40pub use retry::{with_default_retry, with_retry, RetryPolicy};
41pub use verbs::{EncodeBuilder, ForgetBuilder, RecallBuilder};
42
43// HTTP tier — the hosted-edge client (talks to `brain-edge` / the Arc gateway).
44// Only the client + error are re-exported at the root (unique names); the
45// contract types live under `http::` to avoid colliding with the wire types.
46pub use http::{BrainHttpClient, BrainHttpError, HttpRetryPolicy};