From: Kostya Shishkov Date: Wed, 23 Jan 2019 16:56:52 +0000 (+0100) Subject: codebook: make TableDescReader accept non-static tables X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=db63f876c1a23ab4b52629a485aab520101a6345;p=nihav.git codebook: make TableDescReader accept non-static tables --- diff --git a/nihav-core/src/io/codebook.rs b/nihav-core/src/io/codebook.rs index 78ef5ae..285bedd 100644 --- a/nihav-core/src/io/codebook.rs +++ b/nihav-core/src/io/codebook.rs @@ -314,18 +314,18 @@ impl CodebookDescReader for ShortCodebookDescReader { fn len(&mut self) -> usize { self.data.len() } } -pub struct TableCodebookDescReader { - bits: &'static [u8], - codes: &'static [CodeType], +pub struct TableCodebookDescReader<'a, CodeType:'static, IndexType:'static> { + bits: &'a [u8], + codes: &'a [CodeType], idx_map: fn(usize) -> IndexType, } -impl<'a, CodeType, IndexType> TableCodebookDescReader { - pub fn new(codes: &'static [CodeType], bits: &'static [u8], idx_map: fn(usize) -> IndexType) -> Self { +impl<'a, CodeType, IndexType> TableCodebookDescReader<'a, CodeType, IndexType> { + pub fn new(codes: &'a [CodeType], bits: &'a [u8], idx_map: fn(usize) -> IndexType) -> Self { Self { bits, codes, idx_map } } } -impl, IndexType> CodebookDescReader for TableCodebookDescReader +impl<'a, CodeType: Copy+Into, IndexType> CodebookDescReader for TableCodebookDescReader<'a, CodeType, IndexType> { fn bits(&mut self, idx: usize) -> u8 { self.bits[idx] } fn code(&mut self, idx: usize) -> u32 { self.codes[idx].into() }