Incomplete bindings for leveldb for Rust.
snappy
and leveldb
need to be installed. On Ubuntu, I recommend.
sh
sudo apt-get install libleveldb-dev libsnappy-dev
If your project is using Cargo, drop the following lines in your Cargo.toml
:
```text [dependencies]
leveldb = "0.2.0" ```
Make sure you have all prerequisites installed. Run
sh
$ cargo build
for building and
sh
$ cargo test
to run the test suite.
```{.ignore .rust} use std::io::TempDir; use leveldb::database::Database; use leveldb::iterator::Iterable; use leveldb::options::{Options,WriteOptions,ReadOptions};
let tempdir = TempDir::new("demo").unwrap(); let path = tempdir.path().join("simple");
let mut options = Options::new(); options.createifmissing = true; let mut database = match Database::open(path, options) { Ok(db) => { db }, Err(e) => { panic!("failed to open database: {}", e) } };
let writeopts = WriteOptions::new(); match database.put(writeopts, 1, &[1]) { Ok(_) => { () }, Err(e) => { panic!("failed to write to database: {}", e) } };
let readopts = ReadOptions::new(); let res = database.get(readopts, 1); match res { Ok(data) => { assert!(data.issome()); asserteq!(data, Some(vec![1])); } Err(e) => { panic!("failed reading data: {}", e) } }
let iterable: &mut Iterable
let readopts = ReadOptions::new(); let mut iter = database.iter(readopts); let entry = iter.next(); assert_eq!( entry, Some((1, vec![1])) ); ```
MIT, see LICENSE