From a2334ab39ab1dd2cd72cd735b951ae37ed1c5ca3 Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Mon, 7 Sep 2015 18:15:19 -0700 Subject: [PATCH] update README for latest rocksdb version --- README.md | 5 ++++- src/ffi.rs | 15 ++++++++++++++- src/rocksdb.rs | 11 +---------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 6118bd4..baa2f63 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ rust-rocksdb [![Build Status](https://travis-ci.org/spacejam/rust-rocksdb.svg?branch=master)](https://travis-ci.org/spacejam/rust-rocksdb) [![crates.io](http://meritbadge.herokuapp.com/rocksdb)](https://crates.io/crates/rocksdb) -This library has been tested against RocksDB 3.8.1 on linux and OSX. The 0.1.1 crate should work with the Rust 1.2 stable and nightly releases as of 9/7/15. +This library has been tested against RocksDB 3.13.1 on linux and OSX. The 0.1.1 crate should work with the Rust 1.2 stable and nightly releases as of 9/7/15. ### status - [x] basic open/put/get/delete/close @@ -22,6 +22,9 @@ This library has been tested against RocksDB 3.8.1 on linux and OSX. The 0.1.1 Feedback and pull requests welcome! If a particular feature of RocksDB is important to you, please let me know by opening an issue, and I'll prioritize it. ###### Prerequisite: RocksDB + +First, use your system's package manager to install snappy. This is optional, but lets rocksdb take advantage of better compression, and some code may require it. + ```bash wget https://github.com/facebook/rocksdb/archive/rocksdb-3.8.tar.gz tar xvf rocksdb-3.8.tar.gz && cd rocksdb-rocksdb-3.8 && make shared_lib diff --git a/src/ffi.rs b/src/ffi.rs index 5dd20a2..44d57e2 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -15,7 +15,8 @@ */ extern crate libc; use self::libc::{c_char, c_int, c_void, size_t}; -use std::ffi::CString; +use std::ffi::{CString, CStr}; +use std::str::from_utf8; #[derive(Copy, Clone)] #[repr(C)] @@ -92,6 +93,15 @@ pub enum DBUniversalCompactionStyle { rocksdb_total_size_compaction_stop_style = 1, } +pub fn error_message(ptr: *const i8) -> String { + let c_str = unsafe { CStr::from_ptr(ptr) }; + let s = from_utf8(c_str.to_bytes()).unwrap().to_owned(); + unsafe{ + libc::free(ptr as *mut libc::c_void); + } + s +} + //TODO audit the use of boolean arguments, b/c I think they need to be u8 instead... #[link(name = "rocksdb")] extern { @@ -410,6 +420,9 @@ fn internal() { let mut err: *const i8 = 0 as *const i8; let err_ptr: *mut *const i8 = &mut err; let db = rocksdb_open(opts, cpath_ptr, err_ptr); + if !err.is_null() { + println!("failed to open rocksdb: {}", error_message(err)); + } assert!(err.is_null()); let writeopts = rocksdb_writeoptions_create(); diff --git a/src/rocksdb.rs b/src/rocksdb.rs index 20e32b6..4150c31 100644 --- a/src/rocksdb.rs +++ b/src/rocksdb.rs @@ -27,7 +27,7 @@ use std::str::from_utf8; use self::libc::{c_void, size_t}; -use rocksdb_ffi::{self, DBCFHandle}; +use rocksdb_ffi::{self, DBCFHandle, error_message}; use rocksdb_options::Options; pub struct DB { @@ -187,15 +187,6 @@ pub trait Writable { fn delete_cf(&self, cf: DBCFHandle, key: &[u8]) -> Result<(), String>; } -fn error_message(ptr: *const i8) -> String { - let c_str = unsafe { CStr::from_ptr(ptr) }; - let s = from_utf8(c_str.to_bytes()).unwrap().to_owned(); - unsafe{ - libc::free(ptr as *mut libc::c_void); - } - s -} - impl DB { pub fn open_default(path: &str) -> Result { let mut opts = Options::new();