Skip to content

Commit

Permalink
More clippy refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dermesser committed Jun 15, 2024
1 parent 0d24811 commit 0c7da61
Show file tree
Hide file tree
Showing 16 changed files with 308 additions and 300 deletions.
4 changes: 1 addition & 3 deletions examples/kvserver/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use canteen;
use rusty_leveldb;

struct KVService {
db: rusty_leveldb::DB,
Expand Down Expand Up @@ -62,7 +60,7 @@ fn put_key_fn(rq: &canteen::Request) -> canteen::Response {

fn main() {
let db = rusty_leveldb::DB::open("httpdb", rusty_leveldb::Options::default()).unwrap();
let service = KVService { db: db };
let service = KVService { db };
unsafe { STORAGE_SERVICE = Some(std::sync::Mutex::new(service)) };

let mut ct = canteen::Canteen::new();
Expand Down
10 changes: 6 additions & 4 deletions examples/leveldb-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ fn main() {
);
}

let mut opt = Options::default();
opt.reuse_logs = false;
opt.reuse_manifest = false;
opt.compressor = compressor::SnappyCompressor::ID;
let opt = Options {
reuse_logs: false,
reuse_manifest: false,
compressor: compressor::SnappyCompressor::ID,
..Default::default()
};
let mut db = DB::open("tooldb", opt).unwrap();

match args[1].as_str() {
Expand Down
2 changes: 1 addition & 1 deletion examples/mcpe/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn mcpe_options(compression_level: u8) -> Options {
//
// Compression id will be use in [here](https://github.com/reedacartwright/rbedrock/blob/fb32a899da4e15c1aaa0d6de2b459e914e183516/src/leveldb-mcpe/table/format.cc#L125-L150)
let mut list = CompressorList::new();
list.set_with_id(0, NoneCompressor::default());
list.set_with_id(0, NoneCompressor {});
list.set_with_id(2, ZlibCompressor::new(compression_level));
list.set_with_id(4, RawZlibCompressor::new(compression_level));
opt.compressor_list = Rc::new(list);
Expand Down
8 changes: 5 additions & 3 deletions examples/stresstest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn read(db: &mut DB, n: usize) -> usize {
for _ in 0..n {
let k = gen_string(KEY_LEN);

if let Some(_) = db.get(k.as_bytes()) {
if db.get(k.as_bytes()).is_some() {
succ += 1;
}
}
Expand All @@ -48,8 +48,10 @@ fn main() {
let mut entries = 0;

for i in 0..m {
let mut opt = Options::default();
opt.compressor = compressor::SnappyCompressor::ID;
let opt = Options {
compressor: compressor::SnappyCompressor::ID,
..Default::default()
};
let mut db = DB::open(path, opt).unwrap();
write(&mut db, n);
entries += n;
Expand Down
8 changes: 5 additions & 3 deletions examples/word-analyze/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn update_count(w: &str, db: &mut leveldb::DB) -> Option<()> {
let mut count: usize = 0;
if let Some(v) = db.get(w.as_bytes()) {
let s = String::from_utf8(v).unwrap();
count = usize::from_str_radix(&s, 10).unwrap();
count = s.parse::<usize>().unwrap();
}
count += 1;
let s = count.to_string();
Expand All @@ -35,8 +35,10 @@ fn run(mut db: leveldb::DB) -> io::Result<()> {
}

fn main() {
let mut opts = leveldb::Options::default();
opts.compressor = leveldb::compressor::NoneCompressor::ID;
let opts = leveldb::Options {
compressor: leveldb::compressor::NoneCompressor::ID,
..Default::default()
};
let db = leveldb::DB::open("wordsdb", opts).unwrap();

run(db).unwrap();
Expand Down
6 changes: 4 additions & 2 deletions examples/write-a-lot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ fn fill_db(db: &mut DB, entries: usize) -> Result<(), Box<dyn Error>> {
}

fn main() {
let mut opt = Options::default();
opt.compressor = compressor::SnappyCompressor::ID;
let opt = Options {
compressor: compressor::SnappyCompressor::ID,
..Default::default()
};
let mut db = DB::open("test1", opt).unwrap();

fill_db(&mut db, 32768).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/benches/maps_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ fn gen_key_val<R: Rng>(gen: &mut R, keylen: usize, vallen: usize) -> (Vec<u8>, V
let mut val = Vec::with_capacity(vallen);

for _i in 0..keylen {
key.push(gen.gen_range(b'a', b'z'));
key.push(gen.gen_range(b'a'..=b'z'));
}
for _i in 0..vallen {
val.push(gen.gen_range(b'a', b'z'));
val.push(gen.gen_range(b'a'..=b'z'));
}
(key, val)
}
Expand Down
56 changes: 28 additions & 28 deletions src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,15 @@ mod tests {

fn get_data() -> Vec<(&'static [u8], &'static [u8])> {
vec![
("key1".as_bytes(), "value1".as_bytes()),
(b"key1", b"value1"),
(
"loooooooooooooooooooooooooooooooooongerkey1".as_bytes(),
"shrtvl1".as_bytes(),
b"loooooooooooooooooooooooooooooooooongerkey1",
b"shrtvl1",
),
("medium length key 1".as_bytes(), "some value 2".as_bytes()),
("prefix_key1".as_bytes(), "value".as_bytes()),
("prefix_key2".as_bytes(), "value".as_bytes()),
("prefix_key3".as_bytes(), "value".as_bytes()),
(b"prefix_key1", b"value"),
(b"prefix_key2", b"value"),
(b"prefix_key3", b"value"),
]
}

Expand Down Expand Up @@ -358,9 +358,9 @@ mod tests {

let block = Block::new(options::for_test(), blockc);

for _ in LdbIteratorIter::wrap(&mut block.iter()) {
LdbIteratorIter::wrap(&mut block.iter()).for_each(|_| {
panic!("expected 0 iterations");
}
});
}

#[test]
Expand Down Expand Up @@ -403,7 +403,7 @@ mod tests {
assert!(!block.valid());
assert_eq!(
block.next(),
Some(("key1".as_bytes().to_vec(), "value1".as_bytes().to_vec()))
Some((b"key1".to_vec(), b"value1".to_vec()))
);
assert!(block.valid());
block.next();
Expand All @@ -412,22 +412,22 @@ mod tests {
assert!(block.valid());
assert_eq!(
current_key_val(&block),
Some(("key1".as_bytes().to_vec(), "value1".as_bytes().to_vec()))
Some((b"key1".to_vec(), b"value1".to_vec()))
);
block.prev();
assert!(!block.valid());

// Verify that prev() from the last entry goes to the prev-to-last entry
// (essentially, that next() returning None doesn't advance anything)
while let Some(_) = block.next() {}
while block.next().is_some() {}

block.prev();
assert!(block.valid());
assert_eq!(
current_key_val(&block),
Some((
"prefix_key2".as_bytes().to_vec(),
"value".as_bytes().to_vec()
b"prefix_key2".to_vec(),
b"value".to_vec()
))
);
}
Expand All @@ -448,44 +448,44 @@ mod tests {

let mut block = Block::new(o.clone(), block_contents).iter();

block.seek(&"prefix_key2".as_bytes());
block.seek(b"prefix_key2");
assert!(block.valid());
assert_eq!(
current_key_val(&block),
Some((
"prefix_key2".as_bytes().to_vec(),
"value".as_bytes().to_vec()
b"prefix_key2".to_vec(),
b"value".to_vec()
))
);

block.seek(&"prefix_key0".as_bytes());
block.seek(b"prefix_key0");
assert!(block.valid());
assert_eq!(
current_key_val(&block),
Some((
"prefix_key1".as_bytes().to_vec(),
"value".as_bytes().to_vec()
b"prefix_key1".to_vec(),
b"value".to_vec()
))
);

block.seek(&"key1".as_bytes());
block.seek(b"key1");
assert!(block.valid());
assert_eq!(
current_key_val(&block),
Some(("key1".as_bytes().to_vec(), "value1".as_bytes().to_vec()))
Some((b"key1".to_vec(), b"value1".to_vec()))
);

block.seek(&"prefix_key3".as_bytes());
block.seek(b"prefix_key3");
assert!(block.valid());
assert_eq!(
current_key_val(&block),
Some((
"prefix_key3".as_bytes().to_vec(),
"value".as_bytes().to_vec()
b"prefix_key3".to_vec(),
b"value".to_vec()
))
);

block.seek(&"prefix_key8".as_bytes());
block.seek(b"prefix_key8");
assert!(!block.valid());
assert_eq!(current_key_val(&block), None);
}
Expand All @@ -495,7 +495,7 @@ mod tests {
let mut o = options::for_test();

// Test with different number of restarts
for block_restart_interval in vec![2, 6, 10] {
for block_restart_interval in [2, 6, 10] {
o.block_restart_interval = block_restart_interval;

let data = get_data();
Expand All @@ -514,8 +514,8 @@ mod tests {
assert_eq!(
current_key_val(&block),
Some((
"prefix_key3".as_bytes().to_vec(),
"value".as_bytes().to_vec()
b"prefix_key3".to_vec(),
b"value".to_vec()
))
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/blockhandle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ mod tests {
#[test]
fn test_blockhandle() {
let bh = BlockHandle::new(890, 777);
let mut dst = [0 as u8; 128];
let mut dst = [0_u8; 128];
let enc_sz = bh.encode_to(&mut dst[..]);

let (bh2, dec_sz) = BlockHandle::decode(&dst).unwrap();
Expand Down
Loading

0 comments on commit 0c7da61

Please sign in to comment.