fix some warnings (unneeded parentheses, missing dyn keyword)
[nihav.git] / nihav-core / src / io / codebook.rs
index 553f2f9c84e77415580404ae38fb58c092bd465c..0ec88833abb081485acf1e3dd3dec05a603713b0 100644 (file)
@@ -113,6 +113,7 @@ pub struct ShortCodebookDesc {
 ///
 /// [`ShortCodebookDescReader`]: ./struct.ShortCodebookDescReader.html
 /// [`TableCodebookDescReader`]: ./struct.TableCodebookDescReader.html
+#[allow(clippy::len_without_is_empty)]
 pub trait CodebookDescReader<S> {
     /// Returns the codeword length for the provided index.
     fn bits(&mut self, idx: usize) -> u8;
@@ -288,7 +289,7 @@ fn build_esc_lut(table: &mut Vec<u32>,
 impl<S: Copy> Codebook<S> {
 
     /// Constructs a new `Codebook` instance using provided codebook description and mode.
-    pub fn new(cb: &mut CodebookDescReader<S>, mode: CodebookMode) -> CodebookResult<Self> {
+    pub fn new(cb: &mut dyn CodebookDescReader<S>, mode: CodebookMode) -> CodebookResult<Self> {
         let mut maxbits = 0;
         let mut nnz = 0;
         let mut escape_list: EscapeCodes = HashMap::new();
@@ -370,10 +371,10 @@ impl<'a, S: Copy> CodebookReader<S> for BitReader<'a> {
             let bits = cb.table[lut_idx] & 0x7F;
             esc  = (cb.table[lut_idx] & 0x80) != 0;
             idx  = (cb.table[lut_idx] >> 8) as usize;
-            if (bits as isize) > self.left() {
+            let skip_bits = if esc { u32::from(lut_bits) } else { bits };
+            if (skip_bits as isize) > self.left() {
                 return Err(CodebookError::InvalidCode);
             }
-            let skip_bits = if esc { u32::from(lut_bits) } else { bits };
             self.skip(skip_bits as u32).unwrap();
             lut_bits = bits as u8;
         }