changeset 75:1b359f9e98f4

Fix warnings about try!/dyn
author Lewin Bormann <lbo@spheniscida.de>
date Mon, 17 Feb 2020 20:34:46 +0100
parents bc127bc534b5
children 2af70f41377d
files src/table_block.rs src/table_reader.rs
diffstat 2 files changed, 16 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/table_block.rs	Mon Feb 17 20:34:35 2020 +0100
+++ b/src/table_block.rs	Mon Feb 17 20:34:46 2020 +0100
@@ -44,21 +44,21 @@
     // The block is denoted by offset and length in BlockHandle. A block in an encoded
     // table is followed by 1B compression type and 4B checksum.
     // The checksum refers to the compressed contents.
-    let buf = try!(read_bytes(f, location));
-    let compress = try!(read_bytes(
+    let buf = read_bytes(f, location)?;
+    let compress = read_bytes(
         f,
         &BlockHandle::new(
             location.offset() + location.size(),
-            table_builder::TABLE_BLOCK_COMPRESS_LEN
-        )
-    ));
-    let cksum = try!(read_bytes(
+            table_builder::TABLE_BLOCK_COMPRESS_LEN,
+        ),
+    )?;
+    let cksum = read_bytes(
         f,
         &BlockHandle::new(
             location.offset() + location.size() + table_builder::TABLE_BLOCK_COMPRESS_LEN,
-            table_builder::TABLE_BLOCK_CKSUM_LEN
-        )
-    ));
+            table_builder::TABLE_BLOCK_CKSUM_LEN,
+        ),
+    )?;
 
     if !verify_table_block(&buf, compress[0], unmask_crc(u32::decode_fixed(&cksum))) {
         return err(
--- a/src/table_reader.rs	Mon Feb 17 20:34:35 2020 +0100
+++ b/src/table_reader.rs	Mon Feb 17 20:34:46 2020 +0100
@@ -46,17 +46,10 @@
 
     /// Creates a new table reader.
     pub fn new(opt: Options, file: Box<dyn RandomAccess>, size: usize) -> Result<Table> {
-        let footer = try!(read_footer(file.as_ref(), size));
-        let indexblock = try!(table_block::read_table_block(
-            opt.clone(),
-            file.as_ref(),
-            &footer.index
-        ));
-        let metaindexblock = try!(table_block::read_table_block(
-            opt.clone(),
-            file.as_ref(),
-            &footer.meta_index
-        ));
+        let footer = read_footer(file.as_ref(), size)?;
+        let indexblock = table_block::read_table_block(opt.clone(), file.as_ref(), &footer.index)?;
+        let metaindexblock =
+            table_block::read_table_block(opt.clone(), file.as_ref(), &footer.meta_index)?;
 
         let filter_block_reader = Table::read_filter_block(&metaindexblock, file.as_ref(), &opt)?;
         let cache_id = opt.block_cache.borrow_mut().new_cache_id();
@@ -120,11 +113,8 @@
         }
 
         // Two times as_ref(): First time to get a ref from Rc<>, then one from Box<>.
-        let b = try!(table_block::read_table_block(
-            self.opt.clone(),
-            self.file.as_ref().as_ref(),
-            location
-        ));
+        let b =
+            table_block::read_table_block(self.opt.clone(), self.file.as_ref().as_ref(), location)?;
 
         // insert a cheap copy (Rc).
         self.opt
@@ -394,7 +384,7 @@
         (d, size)
     }
 
-    fn wrap_buffer(src: Vec<u8>) -> Box<RandomAccess> {
+    fn wrap_buffer(src: Vec<u8>) -> Box<dyn RandomAccess> {
         Box::new(src)
     }