Inferential Rust SDK
Rust client SDK for Inferential inference orchestration. Communicates with the server using ZMQ DEALER sockets and the shared protobuf wire protocol.
Includes both synchronous (Connection/Model) and async (AsyncConnection/AsyncModel) clients.
Install
Add to your Cargo.toml:
[]
= "0.3"
Or via the CLI:
Requires libzmq installed on the system (apt install libzmq3-dev or brew install zmq).
Build from Source
Requires Rust 1.70+, libzmq installed on the system, and protoc (protobuf compiler).
# Build
# Run tests (single-threaded — tests share ZMQ ports)
# Run examples
# Lint
Or use the root Makefile:
Usage
Sync
use ;
let conn = new;
let model = conn.model;
let joints: = vec!;
model.observe
.urgency
.tensor_f32
.send;
if let Some = model.get_result
conn.close; // also called on Drop
Async
use AsyncConnection;
async
API Reference
Connection (sync)
new
Creates a ZMQ DEALER connection. Auto-prefixes tcp:// if missing. Implements Drop for cleanup.
| Method | Description |
|---|---|
model(model_id, latency_budget_ms, priority) |
Create a Model<'_> handle (borrows connection) |
close() |
Explicit close (also called on drop) |
AsyncConnection
new // async
Tokio-based async connection using the zeromq crate.
| Method | Description |
|---|---|
model(model_id, latency_budget_ms, priority) |
Create an AsyncModel<'_> (requires &mut self) |
close(self) |
Close and consume the connection (async, takes ownership) |
Model<'a> / AsyncModel<'a>
Obtained via conn.model(...). Borrows the connection.
| Method | Sync | Async |
|---|---|---|
observe() |
ObservationBuilder<'_> |
AsyncObservationBuilder<'_> |
get_result(timeout_ms) |
Option<HashMap<String, TensorData>> |
Same, async |
ObservationBuilder / AsyncObservationBuilder
Fluent builder — chain methods and finalize with .send().
| Method | Description |
|---|---|
.urgency(f32) |
Set urgency hint (0.0–1.0) |
.steps_remaining(u32) |
Set remaining trajectory steps |
.tensor(key, data: &[u8], dtype: i32, shape: &[i64]) |
Add raw tensor |
.tensor_f32(key, data: &[f32], shape: &[i64]) |
Add float32 tensor (convenience) |
.metadata(key, value) |
Add string metadata |
.send() |
Serialize and send (async version: .send().await) |
All builder methods consume and return self (move semantics).
TensorData
Holds tensor data received from get_result().
| Method | Return | Description |
|---|---|---|
element_size() |
usize |
Bytes per element |
numel() |
usize |
Total element count |
as_f32() |
&[f32] |
Reinterpret as float32 slice |
as_f64() |
&[f64] |
Reinterpret as float64 slice |
as_i32() |
&[i32] |
Reinterpret as int32 slice |
as_i64() |
&[i64] |
Reinterpret as int64 slice |
as_u8() |
&[u8] |
Raw byte slice |
Complete Example
Sync
use Connection;
use ;
Async
use AsyncConnection;
use ;
async
Notes
- Sync vs Async: The sync client uses the
zmqcrate (libzmq binding). The async client uses thezeromqcrate (native Rust, tokio-based). - Borrow rules:
Modelborrows&Connection,AsyncModelborrows&mut AsyncConnection. Drop the model before callingconn.close(). - Thread safety:
Connectionis notSend/Sync(ZMQ sockets are single-threaded). Create one connection per thread. - Test threading: Tests must run single-threaded (
--test-threads=1) because they bind to fixed ZMQ ports. - Wire protocol: See Architecture for the shared protobuf wire protocol.
Documentation
- Architecture — Wire protocol, system design
- Examples — Multi-language examples
- Contributing — Development workflow