Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

TigerBeetle client.

Provides methods to create accounts, create transfers, and query data. Uses io_uring for high-performance async I/O on Linux.

§Thread Safety

This client is !Send because io_uring submission queues are thread-local. Create one client per thread if you need multi-threaded access.

§Example

use tb_rs::Client;

tokio_uring::start(async {
    // Simple connection
    let mut client = Client::connect(0, "127.0.0.1:3000").await?;

    // Or with custom configuration
    let mut client = Client::builder()
        .cluster(0)
        .addresses("127.0.0.1:3000,127.0.0.1:3001")?
        .connect_timeout(Duration::from_secs(10))
        .build()
        .await?;

    client.close().await;
    Ok::<_, tb_rs::ClientError>(())
});

Implementations§

Source§

impl Client

Source

pub async fn connect(cluster: u128, addresses: &str) -> Result<Self>

Connect to a TigerBeetle cluster.

This is the simplest way to create a client. It connects to the cluster and registers automatically.

§Arguments
  • cluster - Cluster ID (must match the cluster configuration)
  • addresses - Comma-separated replica addresses (e.g., “127.0.0.1:3000”)
§Example
let mut client = Client::connect(0, "127.0.0.1:3000").await?;
Source

pub fn builder() -> ClientBuilder

Create a client builder for custom configuration.

§Example
let client = Client::builder()
    .cluster(0)
    .addresses("127.0.0.1:3000")?
    .connect_timeout(Duration::from_secs(10))
    .request_timeout(Duration::from_millis(100))
    .build()
    .await?;
Source

pub fn id(&self) -> u128

Get the client ID.

Source

pub fn cluster(&self) -> u128

Get the cluster ID.

Source

pub fn is_ready(&self) -> bool

Check if the client is ready for operations.

Source

pub fn batch_size_limit(&self) -> Option<u32>

Get the batch size limit in bytes (available after registration).

Source

pub fn max_batch_count<T>(&self) -> Option<u32>

Get the maximum number of elements that can be sent in a single batch.

This accounts for the multi-batch trailer overhead.

§Example
let max_accounts = client.max_batch_count::<Account>();
let max_transfers = client.max_batch_count::<Transfer>();
Source

pub async fn create_accounts( &mut self, accounts: &[Account], ) -> Result<Vec<CreateAccountsResult>>

Create accounts.

Returns errors for accounts that could not be created. An empty result means all accounts were created successfully.

§Example
let account = Account {
    id: tb_rs::id(),
    ledger: 1,
    code: 1,
    ..Default::default()
};

let errors = client.create_accounts(&[account]).await?;
if errors.is_empty() {
    println!("Account created!");
}
Source

pub async fn create_transfers( &mut self, transfers: &[Transfer], ) -> Result<Vec<CreateTransfersResult>>

Create transfers.

Returns errors for transfers that could not be created. An empty result means all transfers were created successfully.

Source

pub async fn lookup_accounts(&mut self, ids: &[u128]) -> Result<Vec<Account>>

Lookup accounts by ID.

Source

pub async fn lookup_transfers(&mut self, ids: &[u128]) -> Result<Vec<Transfer>>

Lookup transfers by ID.

Source

pub async fn get_account_transfers( &mut self, filter: AccountFilter, ) -> Result<Vec<Transfer>>

Get transfers for an account.

Source

pub async fn get_account_balances( &mut self, filter: AccountFilter, ) -> Result<Vec<AccountBalance>>

Get balance history for an account.

Source

pub async fn query_accounts( &mut self, filter: QueryFilter, ) -> Result<Vec<Account>>

Query accounts.

Source

pub async fn query_transfers( &mut self, filter: QueryFilter, ) -> Result<Vec<Transfer>>

Query transfers.

Source

pub async fn close(self)

Close the client and release resources.

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl !Send for Client

§

impl !Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V