Skip to content

Commit

Permalink
Manually fix some unwraps
Browse files Browse the repository at this point in the history
Enable the warning for growth_ring after manually fixing a few easy
unwraps
  • Loading branch information
rkuris committed Nov 28, 2023
1 parent c0b5b34 commit 809309c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions growth-ring/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ path = "src/lib.rs"
crate-type = ["dylib", "rlib", "staticlib"]

[lints.clippy]
unwrap_used = "warn"
missing_const_for_fn = "warn"
20 changes: 10 additions & 10 deletions growth-ring/examples/demo1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ fn main() -> Result<(), WalError> {
let mut loader = WalLoader::new();
loader.file_nbit(9).block_nbit(8);

let store = WalStoreImpl::new(wal_dir, true).unwrap();
let mut wal = block_on(loader.load(store, recover, 0)).unwrap();
let store = WalStoreImpl::new(wal_dir, true)?;
let mut wal = block_on(loader.load(store, recover, 0))?;
for _ in 0..3 {
let _ = test(
["hi", "hello", "lol"]
Expand All @@ -55,8 +55,8 @@ fn main() -> Result<(), WalError> {
);
}

let store = WalStoreImpl::new(wal_dir, false).unwrap();
let mut wal = block_on(loader.load(store, recover, 0)).unwrap();
let store = WalStoreImpl::new(wal_dir, false)?;
let mut wal = block_on(loader.load(store, recover, 0))?;
for _ in 0..3 {
let _ = test(
vec![
Expand All @@ -69,8 +69,8 @@ fn main() -> Result<(), WalError> {
);
}

let store = WalStoreImpl::new(wal_dir, false).unwrap();
let mut wal = block_on(loader.load(store, recover, 100)).unwrap();
let store = WalStoreImpl::new(wal_dir, false)?;
let mut wal = block_on(loader.load(store, recover, 100))?;
let mut history = std::collections::VecDeque::new();
for _ in 0..3 {
let mut ids = Vec::new();
Expand All @@ -94,17 +94,17 @@ fn main() -> Result<(), WalError> {
ids.shuffle(&mut rng);
for e in ids.chunks(20) {
println!("peel(20)");
futures::executor::block_on(wal.peel(e, 100)).unwrap();
futures::executor::block_on(wal.peel(e, 100))?;
}
}
for (rec, ans) in
block_on(wal.read_recent_records(100, &growthring::wal::RecoverPolicy::Strict))
.unwrap()
?
.into_iter()
.zip(history.into_iter().rev())
{
assert_eq!(std::str::from_utf8(&rec).unwrap(), &ans);
println!("{}", std::str::from_utf8(&rec).unwrap());
assert_eq!(&String::from_utf8_lossy(&rec), &ans);
println!("{}", String::from_utf8_lossy(&rec));
}

Ok(())
Expand Down
1 change: 1 addition & 0 deletions growth-ring/src/wal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,7 @@ impl WalLoader {
pub const CRC32: crc::Crc<u32> = crc::Crc::<u32>::new(&crc::CRC_32_CKSUM);

#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod test {
use super::*;
use test_case::test_case;
Expand Down

0 comments on commit 809309c

Please sign in to comment.