]> git.nihav.org Git - nihav.git/commitdiff
core/codebook: make TableCodebookDescReader accept closures as well
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 9 Nov 2024 17:15:47 +0000 (18:15 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 9 Nov 2024 17:15:47 +0000 (18:15 +0100)
nihav-core/src/io/codebook.rs

index 625009f9784b48e7b836ba245aececa2ecba5ec8..97a6a8d20379e9cc26c02c7320bf40916bf2d493 100644 (file)
@@ -423,13 +423,13 @@ impl<'a> CodebookDescReader<u32> for ShortCodebookDescReader<'a> {
 pub struct TableCodebookDescReader<'a, CodeType:'static, IndexType:'static> {
     bits:       &'a [u8],
     codes:      &'a [CodeType],
-    idx_map:    fn(usize) -> IndexType,
+    idx_map:    Box<dyn Fn(usize) -> IndexType>,
 }
 
 impl<'a, CodeType, IndexType> TableCodebookDescReader<'a, CodeType, IndexType> {
     /// Constructs a new `TableCodebookDescReader` instance.
-    pub fn new(codes: &'a [CodeType], bits: &'a [u8], idx_map: fn(usize) -> IndexType) -> Self {
-        Self { bits, codes, idx_map }
+    pub fn new<MapFunc: Fn(usize) -> IndexType + 'static>(codes: &'a [CodeType], bits: &'a [u8], map_func: MapFunc) -> Self {
+        Self { bits, codes, idx_map: Box::new(map_func) }
     }
 }
 impl<'a, CodeType: Copy+Into<u32>, IndexType> CodebookDescReader<IndexType> for TableCodebookDescReader<'a, CodeType, IndexType>