Programming in Rust

Getting Started

Programming YottaDB in the Rust language is accomplished through yottadb crate, which is a Rust wrapper around the C implementation of YottaDB.

The YottaDB Rust wrapper requires a minimum YottaDB version of r1.30 and is tested with a minimum Rust version of 1.40.

Install YottaDB

Follow the instructions in the Quick Start section to install YottaDB.

Install Rust

The next step is to install Rust. Follow the instructions provided here to get setup with Rust on your system.

Install YDBRust

Clone the YDBRust repository and run an example.

git clone
cd YDBRust
cargo run --example say_hello_rust

There are two major APIs that are part of the Rust wrapper:

  • craw, the FFI bindings generated directly by bindgen. These are not recommended for normal use, but are available in case functionality is needed beyond that provided by the Context API.

  • The main Context API, which is a safe wrapper around the C API which keeps track of the current tptoken and an error buffer. The reason this metadata is necessary is because this crate binds to the threaded version of YottaDB, which requires a tptoken and err_buffer. See transaction processing for more details on tptoken and transactions.

Most operations are encapsulated in methods in the KeyContext struct. Iteration helpers are available to iterate over values in the database in a variety of ways.

Comparison between Rust and Go wrappers

  • Rust has almost no overhead calling into C. There is no reallocation of buffers as with Go.

  • Rust has a context API, not an easy API. The difference is that buffers are re-used between calls so it’s not constantly allocating and deallocating like the Go Easy API does, nor does it require passing in the tptoken and error buffer like the Go Simple API.

  • Rust can pass numbers into M FFI, not just ydb_string_t.