#[tokio::main]
async fn main() {
let network = unsafe { foundationdb::boot() };
hello_world().await.expect("could not run the hello world");
drop(network);
}
async fn hello_world() -> foundationdb::FdbResult<()> {
let db = foundationdb::Database::default()?;
match db
.run(|trx, _maybe_committed| async move {
trx.set(b"hello", b"world");
Ok(())
})
.await
{
Ok(_) => println!("transaction committed"),
Err(_) => eprintln!("cannot commit transaction"),
};
match db
.run(|trx, _maybe_committed| async move { Ok(trx.get(b"hello", false).await.unwrap()) })
.await
{
Ok(slice) => assert_eq!(b"world", slice.unwrap().as_ref()),
Err(_) => eprintln!("cannot commit transaction"),
}
Ok(())
}