|
|
|
@ -111,10 +111,10 @@ pub enum IteratorMode<'a> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl DBIterator { |
|
|
|
|
fn new<'b>(db: &DB, |
|
|
|
|
readopts: &'b ReadOptions, |
|
|
|
|
mode: IteratorMode) |
|
|
|
|
-> DBIterator { |
|
|
|
|
fn new(db: &DB, |
|
|
|
|
readopts: &ReadOptions, |
|
|
|
|
mode: IteratorMode) |
|
|
|
|
-> DBIterator { |
|
|
|
|
unsafe { |
|
|
|
|
let iterator = rocksdb_ffi::rocksdb_create_iterator(db.inner, |
|
|
|
|
readopts.inner); |
|
|
|
@ -274,13 +274,8 @@ impl DB { |
|
|
|
|
let cpath_ptr = cpath.as_ptr(); |
|
|
|
|
|
|
|
|
|
let ospath = Path::new(path); |
|
|
|
|
match fs::create_dir_all(&ospath) { |
|
|
|
|
Err(e) => { |
|
|
|
|
return Err(format!("Failed to create rocksdb directory: \ |
|
|
|
|
{:?}", |
|
|
|
|
e)) |
|
|
|
|
} |
|
|
|
|
Ok(_) => (), |
|
|
|
|
if let Err(e) = fs::create_dir_all(&ospath) { |
|
|
|
|
return Err(format!("Failed to create rocksdb directory: {:?}", e)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let mut err: *const i8 = 0 as *const i8; |
|
|
|
@ -337,7 +332,7 @@ impl DB { |
|
|
|
|
copts, handles, err_ptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for handle in cfhandles.iter() { |
|
|
|
|
for handle in &cfhandles { |
|
|
|
|
if handle.0.is_null() { |
|
|
|
|
return Err("Received null column family handle from DB." |
|
|
|
|
.to_string()); |
|
|
|
@ -411,7 +406,7 @@ impl DB { |
|
|
|
|
if !err.is_null() { |
|
|
|
|
return Err(error_message(err)); |
|
|
|
|
} |
|
|
|
|
return Ok(()); |
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn write(&self, batch: WriteBatch) -> Result<(), String> { |
|
|
|
@ -445,9 +440,10 @@ impl DB { |
|
|
|
|
if !err.is_null() { |
|
|
|
|
return Err(error_message(err)); |
|
|
|
|
} |
|
|
|
|
match val.is_null() { |
|
|
|
|
true => Ok(None), |
|
|
|
|
false => Ok(Some(DBVector::from_c(val, val_len))), |
|
|
|
|
if val.is_null() { |
|
|
|
|
Ok(None) |
|
|
|
|
} else { |
|
|
|
|
Ok(Some(DBVector::from_c(val, val_len))) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -485,9 +481,10 @@ impl DB { |
|
|
|
|
if !err.is_null() { |
|
|
|
|
return Err(error_message(err)); |
|
|
|
|
} |
|
|
|
|
match val.is_null() { |
|
|
|
|
true => Ok(None), |
|
|
|
|
false => Ok(Some(DBVector::from_c(val, val_len))), |
|
|
|
|
if val.is_null() { |
|
|
|
|
Ok(None) |
|
|
|
|
} else { |
|
|
|
|
Ok(Some(DBVector::from_c(val, val_len))) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -750,7 +747,7 @@ impl Drop for WriteBatch { |
|
|
|
|
impl Drop for DB { |
|
|
|
|
fn drop(&mut self) { |
|
|
|
|
unsafe { |
|
|
|
|
for (_, cf) in self.cfs.iter() { |
|
|
|
|
for cf in self.cfs.values() { |
|
|
|
|
rocksdb_ffi::rocksdb_column_family_handle_destroy(*cf); |
|
|
|
|
} |
|
|
|
|
rocksdb_ffi::rocksdb_close(self.inner); |
|
|
|
@ -891,7 +888,7 @@ impl DBVector { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn to_utf8<'a>(&'a self) -> Option<&'a str> { |
|
|
|
|
pub fn to_utf8(&self) -> Option<&str> { |
|
|
|
|
from_utf8(self.deref()).ok() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|