Commit 56ed989e authored by ngaut's avatar ngaut

*: Fix more clippy warnings.

parent 3916a067
...@@ -25,3 +25,4 @@ path = "test/test.rs" ...@@ -25,3 +25,4 @@ path = "test/test.rs"
[dependencies] [dependencies]
libc = "0.1.8" libc = "0.1.8"
clippy = "*"
...@@ -67,19 +67,19 @@ pub fn new_cache(capacity: size_t) -> DBCache { ...@@ -67,19 +67,19 @@ pub fn new_cache(capacity: size_t) -> DBCache {
#[repr(C)] #[repr(C)]
pub enum DBCompressionType { pub enum DBCompressionType {
DBNoCompression = 0, DBNo = 0,
DBSnappyCompression = 1, DBSnappy = 1,
DBZlibCompression = 2, DBZlib = 2,
DBBz2Compression = 3, DBBz2 = 3,
DBLz4Compression = 4, DBLz4 = 4,
DBLz4hcCompression = 5, DBLz4hc = 5,
} }
#[repr(C)] #[repr(C)]
pub enum DBCompactionStyle { pub enum DBCompactionStyle {
DBLevelCompaction = 0, DBLevel = 0,
DBUniversalCompaction = 1, DBUniversal = 1,
DBFifoCompaction = 2, DBFifo = 2,
} }
#[repr(C)] #[repr(C)]
......
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// //
#![feature(plugin)]
#![plugin(clippy)]
pub use ffi as rocksdb_ffi; pub use ffi as rocksdb_ffi;
pub use ffi::{DBCompactionStyle, DBComparator, new_bloom_filter}; pub use ffi::{DBCompactionStyle, DBComparator, new_bloom_filter};
pub use rocksdb::{DB, DBIterator, DBVector, Direction, IteratorMode, Writable, pub use rocksdb::{DB, DBIterator, DBVector, Direction, IteratorMode, Writable,
......
...@@ -144,7 +144,7 @@ fn main() { ...@@ -144,7 +144,7 @@ fn main() {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use rocksdb::{BlockBasedOptions, DB, Options}; use rocksdb::{BlockBasedOptions, DB, Options};
use rocksdb::DBCompactionStyle::DBUniversalCompaction; use rocksdb::DBCompactionStyle::DBUniversal;
fn tuned_for_somebody_elses_disk(path: &str, fn tuned_for_somebody_elses_disk(path: &str,
opts: &mut Options, opts: &mut Options,
...@@ -163,7 +163,7 @@ mod tests { ...@@ -163,7 +163,7 @@ mod tests {
opts.set_min_write_buffer_number_to_merge(4); opts.set_min_write_buffer_number_to_merge(4);
opts.set_level_zero_stop_writes_trigger(2000); opts.set_level_zero_stop_writes_trigger(2000);
opts.set_level_zero_slowdown_writes_trigger(0); opts.set_level_zero_slowdown_writes_trigger(0);
opts.set_compaction_style(DBUniversalCompaction); opts.set_compaction_style(DBUniversal);
opts.set_max_background_compactions(4); opts.set_max_background_compactions(4);
opts.set_max_background_flushes(4); opts.set_max_background_flushes(4);
opts.set_filter_deletes(false); opts.set_filter_deletes(false);
......
...@@ -128,9 +128,10 @@ impl MergeOperands { ...@@ -128,9 +128,10 @@ impl MergeOperands {
impl<'a> Iterator for &'a mut MergeOperands { impl<'a> Iterator for &'a mut MergeOperands {
type Item = &'a [u8]; type Item = &'a [u8];
fn next(&mut self) -> Option<&'a [u8]> { fn next(&mut self) -> Option<&'a [u8]> {
match self.cursor == self.num_operands { if self.cursor == self.num_operands {
true => None, None
false => unsafe { } else {
unsafe {
let base = self.operands_list as usize; let base = self.operands_list as usize;
let base_len = self.operands_list_len as usize; let base_len = self.operands_list_len as usize;
let spacing = mem::size_of::<*const *const u8>(); let spacing = mem::size_of::<*const *const u8>();
...@@ -142,7 +143,7 @@ impl<'a> Iterator for &'a mut MergeOperands { ...@@ -142,7 +143,7 @@ impl<'a> Iterator for &'a mut MergeOperands {
self.cursor += 1; self.cursor += 1;
Some(mem::transmute(slice::from_raw_parts(*(ptr as *const *const u8) Some(mem::transmute(slice::from_raw_parts(*(ptr as *const *const u8)
as *const u8, len))) as *const u8, len)))
}, }
} }
} }
...@@ -160,13 +161,10 @@ fn test_provided_merge(new_key: &[u8], ...@@ -160,13 +161,10 @@ fn test_provided_merge(new_key: &[u8],
-> Vec<u8> { -> Vec<u8> {
let nops = operands.size_hint().0; let nops = operands.size_hint().0;
let mut result: Vec<u8> = Vec::with_capacity(nops); let mut result: Vec<u8> = Vec::with_capacity(nops);
match existing_val { if let Some(v) = existing_val {
Some(v) => { for e in v {
for e in v { result.push(*e);
result.push(*e);
}
} }
None => (),
} }
for op in operands { for op in operands {
for e in op { for e in op {
......
...@@ -111,10 +111,7 @@ pub enum IteratorMode<'a> { ...@@ -111,10 +111,7 @@ pub enum IteratorMode<'a> {
impl DBIterator { impl DBIterator {
fn new<'b>(db: &DB, fn new(db: &DB, readopts: &ReadOptions, mode: IteratorMode) -> DBIterator {
readopts: &'b ReadOptions,
mode: IteratorMode)
-> DBIterator {
unsafe { unsafe {
let iterator = rocksdb_ffi::rocksdb_create_iterator(db.inner, let iterator = rocksdb_ffi::rocksdb_create_iterator(db.inner,
readopts.inner); readopts.inner);
...@@ -249,19 +246,18 @@ impl DB { ...@@ -249,19 +246,18 @@ impl DB {
Err(_) => { Err(_) => {
return Err("Failed to convert path to CString when opening \ return Err("Failed to convert path to CString when opening \
rocksdb" rocksdb"
.to_string()) .to_owned())
} }
}; };
let cpath_ptr = cpath.as_ptr(); let cpath_ptr = cpath.as_ptr();
let ospath = Path::new(path); let ospath = Path::new(path);
match fs::create_dir_all(&ospath) {
Err(e) => { if let Err(e) = fs::create_dir_all(&ospath) {
return Err(format!("Failed to create rocksdb directory: \ return Err(format!("Failed to create rocksdb directory: \
{:?}", src/rocksdb.rs: \
e)) {:?}",
} e));
Ok(_) => (),
} }
let mut err: *const i8 = 0 as *const i8; let mut err: *const i8 = 0 as *const i8;
...@@ -318,15 +314,15 @@ impl DB { ...@@ -318,15 +314,15 @@ impl DB {
copts, handles, err_ptr); copts, handles, err_ptr);
} }
for handle in cfhandles.iter() { for handle in &cfhandles {
if handle.0.is_null() { if handle.0.is_null() {
return Err("Received null column family handle from DB." return Err("Received null column family handle from DB."
.to_string()); .to_owned());
} }
} }
for (n, h) in cfs_v.iter().zip(cfhandles) { for (n, h) in cfs_v.iter().zip(cfhandles) {
cf_map.insert(n.to_string(), h); cf_map.insert((*n).to_owned(), h);
} }
} }
...@@ -334,7 +330,7 @@ impl DB { ...@@ -334,7 +330,7 @@ impl DB {
return Err(error_message(err)); return Err(error_message(err));
} }
if db.0.is_null() { if db.0.is_null() {
return Err("Could not initialize database.".to_string()); return Err("Could not initialize database.".to_owned());
} }
Ok(DB { Ok(DB {
...@@ -392,7 +388,7 @@ impl DB { ...@@ -392,7 +388,7 @@ impl DB {
if !err.is_null() { if !err.is_null() {
return Err(error_message(err)); return Err(error_message(err));
} }
return Ok(()); Ok(())
} }
pub fn write(&self, batch: WriteBatch) -> Result<(), String> { pub fn write(&self, batch: WriteBatch) -> Result<(), String> {
...@@ -407,7 +403,7 @@ impl DB { ...@@ -407,7 +403,7 @@ impl DB {
a fairly trivial call, and its failure may be \ a fairly trivial call, and its failure may be \
indicative of a mis-compiled or mis-loaded \ indicative of a mis-compiled or mis-loaded \
rocksdb library." rocksdb library."
.to_string()); .to_owned());
} }
let val_len: size_t = 0; let val_len: size_t = 0;
...@@ -416,7 +412,7 @@ impl DB { ...@@ -416,7 +412,7 @@ impl DB {
let err_ptr: *mut *const i8 = &mut err; let err_ptr: *mut *const i8 = &mut err;
let val = let val =
rocksdb_ffi::rocksdb_get(self.inner, rocksdb_ffi::rocksdb_get(self.inner,
readopts.clone(), readopts,
key.as_ptr(), key.as_ptr(),
key.len() as size_t, key.len() as size_t,
val_len_ptr, val_len_ptr,
...@@ -425,9 +421,10 @@ impl DB { ...@@ -425,9 +421,10 @@ impl DB {
if !err.is_null() { if !err.is_null() {
return Err(error_message(err)); return Err(error_message(err));
} }
match val.is_null() { if val.is_null() {
true => Ok(None), Ok(None)
false => Ok(Some(DBVector::from_c(val, val_len))), } else {
Ok(Some(DBVector::from_c(val, val_len)))
} }
} }
} }
...@@ -443,7 +440,7 @@ impl DB { ...@@ -443,7 +440,7 @@ impl DB {
a fairly trivial call, and its failure may be \ a fairly trivial call, and its failure may be \
indicative of a mis-compiled or mis-loaded \ indicative of a mis-compiled or mis-loaded \
rocksdb library." rocksdb library."
.to_string()); .to_owned());
} }
let val_len: size_t = 0; let val_len: size_t = 0;
...@@ -452,7 +449,7 @@ impl DB { ...@@ -452,7 +449,7 @@ impl DB {
let err_ptr: *mut *const i8 = &mut err; let err_ptr: *mut *const i8 = &mut err;
let val = let val =
rocksdb_ffi::rocksdb_get_cf(self.inner, rocksdb_ffi::rocksdb_get_cf(self.inner,
readopts.clone(), readopts,
cf, cf,
key.as_ptr(), key.as_ptr(),
key.len() as size_t, key.len() as size_t,
...@@ -462,9 +459,10 @@ impl DB { ...@@ -462,9 +459,10 @@ impl DB {
if !err.is_null() { if !err.is_null() {
return Err(error_message(err)); return Err(error_message(err));
} }
match val.is_null() { if val.is_null() {
true => Ok(None), Ok(None)
false => Ok(Some(DBVector::from_c(val, val_len))), } else {
Ok(Some(DBVector::from_c(val, val_len)))
} }
} }
} }
...@@ -478,7 +476,7 @@ impl DB { ...@@ -478,7 +476,7 @@ impl DB {
Err(_) => { Err(_) => {
return Err("Failed to convert path to CString when opening \ return Err("Failed to convert path to CString when opening \
rocksdb" rocksdb"
.to_string()) .to_owned())
} }
}; };
let cname_ptr = cname.as_ptr(); let cname_ptr = cname.as_ptr();
...@@ -490,7 +488,7 @@ impl DB { ...@@ -490,7 +488,7 @@ impl DB {
opts.inner, opts.inner,
cname_ptr as *const _, cname_ptr as *const _,
err_ptr); err_ptr);
self.cfs.insert(name.to_string(), cf_handler); self.cfs.insert(name.to_owned(), cf_handler);
cf_handler cf_handler
}; };
if !err.is_null() { if !err.is_null() {
...@@ -502,7 +500,7 @@ impl DB { ...@@ -502,7 +500,7 @@ impl DB {
pub fn drop_cf(&mut self, name: &str) -> Result<(), String> { pub fn drop_cf(&mut self, name: &str) -> Result<(), String> {
let cf = self.cfs.get(name); let cf = self.cfs.get(name);
if cf.is_none() { if cf.is_none() {
return Err(format!("Invalid column family: {}", name).to_string()); return Err(format!("Invalid column family: {}", name).clone());
} }
let mut err: *const i8 = 0 as *const i8; let mut err: *const i8 = 0 as *const i8;
...@@ -720,7 +718,7 @@ impl Drop for WriteBatch { ...@@ -720,7 +718,7 @@ impl Drop for WriteBatch {
impl Drop for DB { impl Drop for DB {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
for (_, cf) in self.cfs.iter() { for cf in self.cfs.values() {
rocksdb_ffi::rocksdb_column_family_handle_destroy(*cf); rocksdb_ffi::rocksdb_column_family_handle_destroy(*cf);
} }
rocksdb_ffi::rocksdb_close(self.inner); rocksdb_ffi::rocksdb_close(self.inner);
...@@ -861,7 +859,7 @@ impl DBVector { ...@@ -861,7 +859,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() from_utf8(self.deref()).ok()
} }
} }
......
...@@ -136,12 +136,12 @@ impl Options { ...@@ -136,12 +136,12 @@ impl Options {
} }
} }
pub fn add_merge_operator<'a>(&mut self, pub fn add_merge_operator(&mut self,
name: &str, name: &str,
merge_fn: fn(&[u8], merge_fn: fn(&[u8],
Option<&[u8]>, Option<&[u8]>,
&mut MergeOperands) &mut MergeOperands)
-> Vec<u8>) { -> Vec<u8>) {
let cb = Box::new(MergeOperatorCallback { let cb = Box::new(MergeOperatorCallback {
name: CString::new(name.as_bytes()).unwrap(), name: CString::new(name.as_bytes()).unwrap(),
merge_fn: merge_fn, merge_fn: merge_fn,
...@@ -159,9 +159,9 @@ impl Options { ...@@ -159,9 +159,9 @@ impl Options {
} }
} }
pub fn add_comparator<'a>(&mut self, pub fn add_comparator(&mut self,
name: &str, name: &str,
compare_fn: fn(&[u8], &[u8]) -> i32) { compare_fn: fn(&[u8], &[u8]) -> i32) {
let cb = Box::new(ComparatorCallback { let cb = Box::new(ComparatorCallback {
name: CString::new(name.as_bytes()).unwrap(), name: CString::new(name.as_bytes()).unwrap(),
f: compare_fn, f: compare_fn,
...@@ -193,13 +193,10 @@ impl Options { ...@@ -193,13 +193,10 @@ impl Options {
pub fn set_use_fsync(&mut self, useit: bool) { pub fn set_use_fsync(&mut self, useit: bool) {
unsafe { unsafe {
match useit { if useit {
true => { rocksdb_ffi::rocksdb_options_set_use_fsync(self.inner, 1)
rocksdb_ffi::rocksdb_options_set_use_fsync(self.inner, 1) } else {
} rocksdb_ffi::rocksdb_options_set_use_fsync(self.inner, 0)
false => {
rocksdb_ffi::rocksdb_options_set_use_fsync(self.inner, 0)
}
} }
} }
} }
...@@ -212,13 +209,12 @@ impl Options { ...@@ -212,13 +209,12 @@ impl Options {
pub fn set_disable_data_sync(&mut self, disable: bool) { pub fn set_disable_data_sync(&mut self, disable: bool) {
unsafe { unsafe {
match disable { if disable {
true => rocksdb_ffi::rocksdb_options_set_disable_data_sync(self.inner,
rocksdb_ffi::rocksdb_options_set_disable_data_sync( 1);
self.inner, 1), } else {
false => rocksdb_ffi::rocksdb_options_set_disable_data_sync(self.inner,
rocksdb_ffi::rocksdb_options_set_disable_data_sync( 0);
self.inner, 0),
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment