#minimal #typing #key #bindings #leveldb

leveldb_minimal

An minimal interface for leveldb

1 unstable release

Uses old Rust 2015

0.1.0 Sep 12, 2020
Download history 139/week @ 2021-05-10 123/week @ 2021-05-17 35/week @ 2021-05-24 50/week @ 2021-05-31 5/week @ 2021-06-07 3/week @ 2021-06-14 7/week @ 2021-06-21 12/week @ 2021-06-28 1/week @ 2021-07-19 1/week @ 2021-07-26 3/week @ 2021-08-02 2/week @ 2021-08-16 1/week @ 2021-08-23

200 downloads per month

MIT license

41KB
925 lines

Rust leveldb bindings

Minimal bindings for leveldb for Rust.

This crate is a fork of leveldb that:

  • removes the typing of the key
  • removes iterators on keys or values only
  • resolves warning clippings

Goal

The goal of this fork is to be used as a backend of the kv_typed crate which already handles typing and iterators on keys or values only.

Rust version policy

leveldb is built and tested on stable releases of Rust. This are currently 1.46.0. Nightlies might not build at any point and failures are allowed.

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-minimal = "0.1"

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((vec![1], vec![1]))
  );
}

License

MIT, see LICENSE

Dependencies

~1.5MB
~25K SLoC