fix some clippy warnings

master
Tyler Neely 8 years ago
parent c18043f427
commit 8f445220bb
No known key found for this signature in database
GPG Key ID: 23E6C4FBEAE5E4E3
  1. 18
      src/ffi.rs
  2. 13
      src/main.rs
  3. 18
      src/merge_operator.rs
  4. 39
      src/rocksdb.rs
  5. 54
      src/rocksdb_options.rs

@ -67,19 +67,19 @@ pub fn new_cache(capacity: size_t) -> DBCache {
#[repr(C)]
pub enum DBCompressionType {
DBNoCompression = 0,
DBSnappyCompression = 1,
DBZlibCompression = 2,
DBBz2Compression = 3,
DBLz4Compression = 4,
DBLz4hcCompression = 5,
None = 0,
Snappy = 1,
Zlib = 2,
Bz2 = 3,
Lz4 = 4,
Lz4hc = 5,
}
#[repr(C)]
pub enum DBCompactionStyle {
DBLevelCompaction = 0,
DBUniversalCompaction = 1,
DBFifoCompaction = 2,
Level = 0,
Universal = 1,
Fifo = 2,
}
#[repr(C)]

@ -71,13 +71,10 @@ fn concat_merge(_: &[u8],
operands: &mut MergeOperands)
-> Vec<u8> {
let mut result: Vec<u8> = Vec::with_capacity(operands.size_hint().0);
match existing_val {
Some(v) => {
for e in v {
result.push(*e)
}
if let Some(v) = existing_val {
for e in v {
result.push(*e)
}
None => (),
}
for op in operands {
for e in op {
@ -144,7 +141,7 @@ fn main() {
#[cfg(test)]
mod tests {
use rocksdb::{BlockBasedOptions, DB, Options};
use rocksdb::DBCompactionStyle::DBUniversalCompaction;
use rocksdb::DBCompactionStyle::Universal;
fn tuned_for_somebody_elses_disk(path: &str,
opts: &mut Options,
@ -163,7 +160,7 @@ mod tests {
opts.set_min_write_buffer_number_to_merge(4);
opts.set_level_zero_stop_writes_trigger(2000);
opts.set_level_zero_slowdown_writes_trigger(0);
opts.set_compaction_style(DBUniversalCompaction);
opts.set_compaction_style(Universal);
opts.set_max_background_compactions(4);
opts.set_max_background_flushes(4);
opts.set_filter_deletes(false);

@ -128,9 +128,10 @@ impl MergeOperands {
impl<'a> Iterator for &'a mut MergeOperands {
type Item = &'a [u8];
fn next(&mut self) -> Option<&'a [u8]> {
match self.cursor == self.num_operands {
true => None,
false => unsafe {
if self.cursor == self.num_operands {
None
} else {
unsafe {
let base = self.operands_list as usize;
let base_len = self.operands_list_len as usize;
let spacing = mem::size_of::<*const *const u8>();
@ -142,7 +143,7 @@ impl<'a> Iterator for &'a mut MergeOperands {
self.cursor += 1;
Some(mem::transmute(slice::from_raw_parts(*(ptr as *const *const u8)
as *const u8, len)))
},
}
}
}
@ -160,13 +161,10 @@ fn test_provided_merge(new_key: &[u8],
-> Vec<u8> {
let nops = operands.size_hint().0;
let mut result: Vec<u8> = Vec::with_capacity(nops);
match existing_val {
Some(v) => {
for e in v {
result.push(*e);
}
if let Some(v) = existing_val {
for e in v {
result.push(*e);
}
None => (),
}
for op in operands {
for e in op {

@ -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()
}
}

@ -136,12 +136,12 @@ impl Options {
}
}
pub fn add_merge_operator<'a>(&mut self,
name: &str,
merge_fn: fn(&[u8],
Option<&[u8]>,
&mut MergeOperands)
-> Vec<u8>) {
pub fn add_merge_operator(&mut self,
name: &str,
merge_fn: fn(&[u8],
Option<&[u8]>,
&mut MergeOperands)
-> Vec<u8>) {
let cb = Box::new(MergeOperatorCallback {
name: CString::new(name.as_bytes()).unwrap(),
merge_fn: merge_fn,
@ -159,9 +159,9 @@ impl Options {
}
}
pub fn add_comparator<'a>(&mut self,
name: &str,
compare_fn: fn(&[u8], &[u8]) -> i32) {
pub fn add_comparator(&mut self,
name: &str,
compare_fn: fn(&[u8], &[u8]) -> i32) {
let cb = Box::new(ComparatorCallback {
name: CString::new(name.as_bytes()).unwrap(),
f: compare_fn,
@ -193,13 +193,10 @@ impl Options {
pub fn set_use_fsync(&mut self, useit: bool) {
unsafe {
match useit {
true => {
rocksdb_ffi::rocksdb_options_set_use_fsync(self.inner, 1)
}
false => {
rocksdb_ffi::rocksdb_options_set_use_fsync(self.inner, 0)
}
if useit {
rocksdb_ffi::rocksdb_options_set_use_fsync(self.inner, 1)
} else {
rocksdb_ffi::rocksdb_options_set_use_fsync(self.inner, 0)
}
}
}
@ -212,13 +209,10 @@ impl Options {
pub fn set_disable_data_sync(&mut self, disable: bool) {
unsafe {
match disable {
true =>
rocksdb_ffi::rocksdb_options_set_disable_data_sync(
self.inner, 1),
false =>
rocksdb_ffi::rocksdb_options_set_disable_data_sync(
self.inner, 0),
if disable {
rocksdb_ffi::rocksdb_options_set_disable_data_sync(self.inner, 1)
} else {
rocksdb_ffi::rocksdb_options_set_disable_data_sync(self.inner, 0)
}
}
}
@ -308,15 +302,13 @@ impl Options {
}
pub fn set_disable_auto_compactions(&mut self, disable: bool) {
let c_bool = if disable {
1
} else {
0
};
unsafe {
match disable {
true =>
rocksdb_ffi::rocksdb_options_set_disable_auto_compactions(
self.inner, 1),
false =>
rocksdb_ffi::rocksdb_options_set_disable_auto_compactions(
self.inner, 0),
}
rocksdb_ffi::rocksdb_options_set_disable_auto_compactions(self.inner, c_bool)
}
}

Loading…
Cancel
Save