Skip to main content

Crate tarant

Crate tarant 

Source
Expand description

An async Tarantool client that speaks the binary protocol natively, is typed end to end, and stays out of your way.

use serde::{Deserialize, Serialize};
use tarant::{Client, Iter, Update};

#[derive(Serialize, Deserialize)]
struct User {
    id: u64,
    name: String,
    age: u32,
}

let client = Client::connect("tarantool://app:secret@127.0.0.1:3301").await?;
let users = client.space::<User>("users");

users.insert(&User { id: 1, name: "ann".into(), age: 30 }).await?;

let ann: Option<User> = users.get(1).await?;
let adults: Vec<User> = users.index("age").select(18).iterator(Iter::Ge).limit(100).await?;

users.update(1, Update::new().set(3, 31)).await?;

§How it fits together

  • One connection, many requests. A Client is a cheap handle onto a background task that owns the socket. Requests are pipelined and matched to replies by their sync, so concurrent callers never queue behind one another. Cloning a Client shares that connection.
  • Types at the boundary. A tuple is anything serde turns into a MessagePack array: a struct, a tuple, a Vec. Keys (Key), call arguments (Args) and field operations (Update) are checked by the compiler before a byte reaches the wire.
  • Errors you can branch on. A server rejection arrives as ServerError carrying the numeric ErrorCode and the full error stack — match on ErrorCode::TUPLE_FOUND, never on a message string.
  • Reconnects that keep their promises. A dropped link is re-established with backoff, the handshake replayed and every Watcher re-subscribed. Requests that were in flight fail with Error::Closed, because the client cannot know whether the server ran them.
  • Nothing unsafe, nothing hidden. #![forbid(unsafe_code)], every public item documented, no panics on user input.

§Feature flags

  • uuid — accept uuid::Uuid directly as a key field.

§Compatibility

Requires Tarantool 3.0 or later for space operations: the client addresses spaces and indexes by name, which the protocol gained in 3.0, so there is no schema fetch and no id cache to go stale. Against 2.10–2.11, call, eval, transactions and watchers still work; Client::server_info reports what the handshake negotiated.

Re-exports§

pub use types::Datetime;
pub use types::Decimal;
pub use types::Interval;
pub use types::Uuid;

Modules§

sql
SQL over the binary protocol: box.execute and box.prepare, from Rust.
types
Tarantool’s extension value types: Decimal, Uuid, Datetime, Interval.

Structs§

Client
A connection to a Tarantool instance.
ConnectOptions
Connection settings for a Client.
ErrorCode
A Tarantool error code (box.error.*, errcode.h).
Index
A secondary index, reached with Space::index.
Page
One page of a Select::page walk: the rows, and where to resume.
Paged
A Select that will return a Page. Await it.
PushCall
A running call whose function pushes values before it returns.
Select
A select in the making.
ServerError
An error raised by the server, decoded from the MP_ERROR extension.
ServerInfo
What the server told us about itself during the handshake.
Space
Typed CRUD over one space, addressed by name.
Stream
An ordered request sequence, and the scope of an interactive transaction.
TxOptions
How a transaction behaves: isolation, and how long the server waits.
Update
An ordered list of field operations.
Watcher
A live subscription to a broadcast key.

Enums§

Error
Every failure a tarant operation can produce.
Feature
Protocol features, as listed in iproto_features.h.
FieldRef
A field to modify: a 1-based position or a JSON path.
Isolation
Isolation level of a stream transaction.
Iter
How select walks an index.
Reconnect
Reconnection policy after the connection is lost.
Value
A dynamically typed MessagePack value, re-exported from rmpv.

Constants§

DEFAULT_PORT
Default iproto port.

Traits§

Args
Arguments of a stored-procedure call or a Lua eval.
Key
A lookup key: one or more field values, in index order.

Type Aliases§

Result
A specialised Result for tarant operations.