@@ -8,6 +8,7 @@ use std::{
88use bitvec:: { boxed:: BitBox , order:: Msb0 , slice:: BitSlice , vec:: BitVec , view:: AsBits } ;
99
1010use crate :: {
11+ Context ,
1112 r#as:: { BorrowCow , Same } ,
1213 de:: { BitReader , BitReaderExt , BitUnpackAs } ,
1314 ser:: { BitPackAs , BitWriter , BitWriterExt } ,
@@ -39,7 +40,8 @@ impl<As: ?Sized, const BITS: usize> VarLen<As, BITS> {
3940 {
4041 let iter = source. into_iter ( ) ;
4142 writer
42- . pack_as :: < _ , NBits < BITS > > ( iter. len ( ) , ( ) ) ?
43+ . pack_as :: < _ , NBits < BITS > > ( iter. len ( ) , ( ) )
44+ . context ( "length" ) ?
4345 . pack_many_as :: < _ , <& ' a As as IntoIterator >:: Item > ( iter, args) ?;
4446 Ok ( ( ) )
4547 }
@@ -56,7 +58,7 @@ impl<As: ?Sized, const BITS: usize> VarLen<As, BITS> {
5658 As :: Item : BitUnpackAs < ' de , <T as IntoIterator >:: Item > ,
5759 <As :: Item as BitUnpackAs < ' de , <T as IntoIterator >:: Item > >:: Args : Clone ,
5860 {
59- let len: usize = reader. unpack_as :: < _ , NBits < BITS > > ( ( ) ) ?;
61+ let len: usize = reader. unpack_as :: < _ , NBits < BITS > > ( ( ) ) . context ( "length" ) ?;
6062 reader
6163 . unpack_iter_as :: < _ , As :: Item > ( args)
6264 . take ( len)
@@ -77,7 +79,8 @@ impl<const BITS: usize> BitPackAs<BitSlice<u8, Msb0>> for VarLen<Same, BITS> {
7779 W : BitWriter + ?Sized ,
7880 {
7981 writer
80- . pack_as :: < _ , NBits < BITS > > ( source. len ( ) , ( ) ) ?
82+ . pack_as :: < _ , NBits < BITS > > ( source. len ( ) , ( ) )
83+ . context ( "length" ) ?
8184 . write_bitslice ( source)
8285 }
8386}
@@ -133,7 +136,7 @@ impl<'de: 'a, 'a, const BITS: usize> BitUnpackAs<'de, Cow<'a, BitSlice<u8, Msb0>
133136 where
134137 R : BitReader < ' de > + ?Sized ,
135138 {
136- let len = reader. unpack_as :: < _ , NBits < BITS > > ( ( ) ) ?;
139+ let len = reader. unpack_as :: < _ , NBits < BITS > > ( ( ) ) . context ( "length" ) ?;
137140 reader. unpack_as :: < _ , BorrowCow > ( len)
138141 }
139142}
@@ -175,7 +178,8 @@ impl<const BITS: usize> BitPackAs<[u8]> for VarLen<Same, BITS> {
175178 W : BitWriter + ?Sized ,
176179 {
177180 writer
178- . pack_as :: < _ , NBits < BITS > > ( source. len ( ) , ( ) ) ?
181+ . pack_as :: < _ , NBits < BITS > > ( source. len ( ) , ( ) )
182+ . context ( "length" ) ?
179183 . write_bitslice ( source. as_bits ( ) )
180184 }
181185}
@@ -201,7 +205,7 @@ impl<'de: 'a, 'a, const BITS: usize> BitUnpackAs<'de, Cow<'a, [u8]>> for VarLen<
201205 where
202206 R : BitReader < ' de > + ?Sized ,
203207 {
204- let len: usize = reader. unpack_as :: < _ , NBits < BITS > > ( ( ) ) ?;
208+ let len: usize = reader. unpack_as :: < _ , NBits < BITS > > ( ( ) ) . context ( "length" ) ?;
205209 reader. unpack_as :: < _ , BorrowCow > ( len)
206210 }
207211}
@@ -609,7 +613,7 @@ impl<'de: 'a, 'a, const BITS: usize> BitUnpackAs<'de, Cow<'a, str>> for VarLen<S
609613 where
610614 R : BitReader < ' de > + ?Sized ,
611615 {
612- let len: usize = reader. unpack_as :: < _ , NBits < BITS > > ( ( ) ) ?;
616+ let len: usize = reader. unpack_as :: < _ , NBits < BITS > > ( ( ) ) . context ( "length" ) ?;
613617 reader. unpack_as :: < _ , BorrowCow > ( len)
614618 }
615619}
0 commit comments