Crates.io | exonum_leveldb |
lib.rs | exonum_leveldb |
version | 0.9.1 |
source | src |
created_at | 2017-07-17 06:48:57.726689 |
updated_at | 2017-09-13 15:13:01.687615 |
description | An interface for leveldb |
homepage | |
repository | https://github.com/exonum/exonum |
max_upload_size | |
id | 23724 |
size | 52,038 |
Incomplete bindings for leveldb for Rust.
leveldb
is built and tested on stable releases of Rust. This is currently 1.0.0-beta
. Nightlies
might not build at any point and failures are allowed.
snappy
and leveldb
need to be installed. On Ubuntu, I recommend.
sudo apt-get install libleveldb-dev libsnappy-dev
If your project is using Cargo, drop the following lines in your Cargo.toml
:
[dependencies]
leveldb = "*"
Make sure you have all prerequisites installed. Run
$ cargo build
for building and
$ cargo test
to run the test suite.
#[allow(unstable)]
extern crate leveldb;
use std::fs::TempDir;
use leveldb::database::Database;
use leveldb::iterator::Iterable;
use leveldb::options::{Options,WriteOptions,ReadOptions};
fn main() {
let tempdir = TempDir::new("demo").unwrap();
let path = tempdir.path();
let mut options = Options::new();
options.create_if_missing = true;
let mut database = match Database::open(path, options) {
Ok(db) => { db },
Err(e) => { panic!("failed to open database: {:?}", e) }
};
let write_opts = WriteOptions::new();
match database.put(write_opts, 1, &[1]) {
Ok(_) => { () },
Err(e) => { panic!("failed to write to database: {:?}", e) }
};
let read_opts = ReadOptions::new();
let res = database.get(read_opts,
1);
match res {
Ok(data) => {
assert!(data.is_some());
assert_eq!(data, Some(vec![1]));
}
Err(e) => { panic!("failed reading data: {:?}", e) }
}
let read_opts = ReadOptions::new();
let mut iter = database.iter(read_opts);
let entry = iter.next();
assert_eq!(
entry,
Some((1, vec![1]))
);
}
MIT, see LICENSE