From 9e33a8dcb5e08e4c1c5615eee269377d183ad021 Mon Sep 17 00:00:00 2001 From: Marius Cobzarenco Date: Mon, 23 Feb 2015 18:55:21 +0000 Subject: [PATCH] Updated to compile with rustc 1.0.0.alpha.2 --- src/lib.rs | 8 +++++++- src/main.rs | 3 ++- src/merge_operator.rs | 8 ++++---- src/rocksdb.rs | 35 ++++++++++++++++------------------- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6ddfa63..da3be2a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,7 +15,13 @@ */ #![crate_id = "rocksdb"] #![crate_type = "lib"] -#![allow(dead_code)] +#![feature(collections)] +#![feature(core)] +#![feature(fs)] +#![feature(io)] +#![feature(libc)] +#![feature(path)] +#![feature(std_misc)] pub use ffi as rocksdb_ffi; pub use ffi::{ diff --git a/src/main.rs b/src/main.rs index 8f10bcc..1c62bdf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -#![allow(unstable)] +#![feature(collections)] +#![feature(test)] extern crate rocksdb; extern crate test; diff --git a/src/merge_operator.rs b/src/merge_operator.rs index 61b6c68..9f5f6da 100644 --- a/src/merge_operator.rs +++ b/src/merge_operator.rs @@ -101,17 +101,17 @@ pub extern "C" fn partial_merge_callback( } -pub struct MergeOperands<'a> { +pub struct MergeOperands { operands_list: *const *const c_char, operands_list_len: *const size_t, num_operands: usize, cursor: usize, } -impl <'a> MergeOperands<'a> { +impl MergeOperands { fn new(operands_list: *const *const c_char, operands_list_len: *const size_t, - num_operands: c_int) -> MergeOperands<'a> { + num_operands: c_int) -> MergeOperands { assert!(num_operands >= 0); MergeOperands { operands_list: operands_list, @@ -122,7 +122,7 @@ impl <'a> MergeOperands<'a> { } } -impl<'a> Iterator for &'a mut MergeOperands<'a> { +impl<'a> Iterator for &'a mut MergeOperands { type Item = &'a [u8]; fn next(&mut self) -> Option<&'a [u8]> { use std::raw::Slice; diff --git a/src/rocksdb.rs b/src/rocksdb.rs index a3e4b69..87ee485 100644 --- a/src/rocksdb.rs +++ b/src/rocksdb.rs @@ -13,19 +13,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -#![allow(unstable)] extern crate libc; use self::libc::{c_void, size_t}; +use std::ffi::CString; +use std::fs::{self, PathExt}; use std::ops::Deref; +use std::path::Path; use std::ptr::Unique; -use std::ffi::CString; -use std::str::from_utf8; use std::slice; use std::str::from_c_str; -use std::io::fs::PathExtensions; -use std::io; -use std::io::fs; +use std::str::from_utf8; use rocksdb_ffi; use rocksdb_ffi::RocksDBSnapshot; @@ -49,8 +47,8 @@ impl RocksDB { let ospath = Path::new(path); if !ospath.exists() { - match fs::mkdir_recursive(&ospath, io::USER_DIR) { - Err(e) => return Err(e.desc), + match fs::create_dir_all(&ospath) { + Err(e) => return Err(""), Ok(_) => (), } } @@ -146,8 +144,7 @@ impl RocksDB { } } - pub fn get<'a>(&self, key: &[u8]) -> - RocksDBResult<'a, RocksDBVector, &str> { + pub fn get(&self, key: &[u8]) -> RocksDBResult { unsafe { let readopts = rocksdb_ffi::rocksdb_readoptions_create(); if readopts.0.is_null() { @@ -202,14 +199,14 @@ pub struct RocksDBVector { impl Deref for RocksDBVector { type Target = [u8]; fn deref(&self) -> &[u8] { - unsafe { slice::from_raw_mut_buf(&self.base.0, self.len) } + unsafe { slice::from_raw_mut_buf(self.base.deref(), self.len) } } } impl Drop for RocksDBVector { fn drop(&mut self) { unsafe { - libc::free(self.base.0 as *mut libc::c_void); + libc::free(*self.base.deref() as *mut libc::c_void); } } } @@ -217,7 +214,7 @@ impl Drop for RocksDBVector { impl RocksDBVector { pub fn from_c(val: *mut u8, val_len: size_t) -> RocksDBVector { unsafe { - let base = Unique(val); + let base = Unique::new(val); RocksDBVector { base: base, len: val_len as usize, @@ -232,15 +229,15 @@ impl RocksDBVector { // RocksDBResult exists because of the inherent difference between // an operational failure and the absence of a possible result. -#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Show)] -pub enum RocksDBResult<'a,T,E> { +#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Debug)] +pub enum RocksDBResult { Some(T), None, Error(E), } -impl <'a,T,E> RocksDBResult<'a,T,E> { - pub fn map U>(self, f: F) -> RocksDBResult<'a,U,E> { +impl RocksDBResult { + pub fn map U>(self, f: F) -> RocksDBResult { match self { RocksDBResult::Some(x) => RocksDBResult::Some(f(x)), RocksDBResult::None => RocksDBResult::None, @@ -258,7 +255,7 @@ impl <'a,T,E> RocksDBResult<'a,T,E> { } } - pub fn on_error U>(self, f: F) -> RocksDBResult<'a,T,U> { + pub fn on_error U>(self, f: F) -> RocksDBResult { match self { RocksDBResult::Some(x) => RocksDBResult::Some(x), RocksDBResult::None => RocksDBResult::None, @@ -266,7 +263,7 @@ impl <'a,T,E> RocksDBResult<'a,T,E> { } } - pub fn on_absent()>(self, f: F) -> RocksDBResult<'a,T,E> { + pub fn on_absent()>(self, f: F) -> RocksDBResult { match self { RocksDBResult::Some(x) => RocksDBResult::Some(x), RocksDBResult::None => {