24 releases

Uses old Rust 2015

0.8.6 Sep 20, 2020
0.8.5 Jun 4, 2020
0.8.4 Sep 20, 2017
0.8.3 Dec 23, 2015
0.2.0 Nov 25, 2014

#228 in Database interfaces

Download history 10125/week @ 2024-07-23 10156/week @ 2024-07-30 9797/week @ 2024-08-06 10139/week @ 2024-08-13 9069/week @ 2024-08-20 9930/week @ 2024-08-27 9803/week @ 2024-09-03 9041/week @ 2024-09-10 8975/week @ 2024-09-17 8451/week @ 2024-09-24 8250/week @ 2024-10-01 8891/week @ 2024-10-08 10660/week @ 2024-10-15 11704/week @ 2024-10-22 10554/week @ 2024-10-29 7827/week @ 2024-11-05

42,150 downloads per month
Used in 19 crates (15 directly)

MIT license

52KB
1K SLoC

Rust leveldb bindings

Almost-complete bindings for leveldb for Rust.

Documentation

Rust version policy

leveldb is built and tested on stable releases of Rust. This are currently 1.31.0 and 1.43.1. Nightlies might not build at any point and failures are allowed. There are no known issues with nightlies, though.

Prerequisites

snappy and leveldb need to be installed. On Ubuntu, I recommend:

sudo apt-get install libleveldb-dev libsnappy-dev

Usage

If your project is using Cargo, drop the following lines in your Cargo.toml:

[dependencies]

leveldb = "0.8"

Development

Make sure you have all prerequisites installed. Run

$ cargo build

for building and

$ cargo test

to run the test suite.

Examples

extern crate tempdir;
extern crate leveldb;

use tempdir::TempDir;
use leveldb::database::Database;
use leveldb::iterator::Iterable;
use leveldb::kv::KV;
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]))
  );
}

Open issues

  • Filter policies are missing
  • Iterators with arbirary start and end points are unsupported

License

MIT, see LICENSE

Dependencies

~1.5MB
~29K SLoC