FoundationDB Rust Client API
This is a wrapper library around the FoundationDB (Fdb) C API. It implements futures based interfaces over the Fdb future C implementations.
Prerequisites
Install FoundationDB
Install FoundationDB on your system, see FoundationDB Local Development, or these instructions:
- Ubuntu Linux (this may work on the Linux subsystem for Windows as well)
$> curl -O https://www.foundationdb.org/downloads/5.1.5/ubuntu/installers/foundationdb-clients_5.1.5-1_amd64.deb
$> curl -O https://www.foundationdb.org/downloads/5.1.5/ubuntu/installers/foundationdb-server_5.1.5-1_amd64.deb
$> sudo dpkg -i foundationdb-clients_5.1.5-1_amd64.deb
$> sudo dpkg -i foundationdb-server_5.1.5-1_amd64.deb
- macOS
$> curl -O https://www.foundationdb.org/downloads/5.1.5/macOS/installers/FoundationDB-5.1.5.pkg
$> sudo installer -pkg FoundationDB-5.1.5.pkg -target /
Add dependencies on foundationdb-rs
[]
= "*"
Extern the crate in bin.rs
or lib.rs
extern crate foundationdb;
Initialization
Due to limitations in the C API, the Client and it's associated Network can only be initialized and run once per the life of a process. Generally the foundationdb::init
function will be enough to initialize the Client. See foundationdb::default_api
and foundationdb::builder
for more configuration options of the Fdb Client.
Example
extern crate futures;
extern crate foundationdb;
use thread;
use *;
use ;
let network = init.expect;
let handle = spawn;
// wait for the network thread to be started
network.wait;
// work with Fdb
let db = new
.and_then
.wait.expect;
// set a value
let trx = db.create_trx.expect;
trx.set; // errors will be returned in the future result
trx.commit
.wait
.expect;
// read a value
let trx = db.create_trx.expect;
let result = trx.get.wait.expect;
let value: & = result.value
.expect // unwrap the error
.unwrap; // unwrap the option
// should print "hello world"
println!;
// cleanly shutdown the client
network.stop.expect;
handle.join;
API stability
WARNING Until the 1.0 release of this library, the API may be in constant flux.