Rust bindings for Berkeley DB
use libdb::Flags;
let env = libdb::EnvironmentBuilder::new()
.flags(Flags::DB_CREATE | Flags::DB_RECOVER | Flags::DB_INIT_TXN | Flags::DB_INIT_MPOOL)
.open()
.unwrap();
let txn = env.txn(None, Flags::DB_NONE).unwrap();
let db = libdb::DatabaseBuilder::new()
.environment(&env)
.transaction(&txn)
.flags(Flags::DB_CREATE)
.open()
.unwrap();
txn.commit(libdb::CommitType::Inherit).expect("Commit failed!");
let mut key = String::from("key").into_bytes();
let mut value = String::from("value").into_bytes();
assert!(db.put(None, key.as_mut_slice(), value.as_mut_slice(), Flags::DB_NONE).is_ok());
let ret = db.get(None, key.as_mut_slice(), Flags::DB_NONE);
assert!(ret.is_ok());
assert_eq!("value", str::from_utf8(ret.ok().unwrap().unwrap().as_slice()).unwrap());