feat: decode proto list and proto pair

Co-authored-by: Kasey White <kwhitemsg@gmail.com>
This commit is contained in:
rvcas
2022-08-05 00:23:26 -04:00
committed by Lucas
parent e8f783e7bb
commit b83394be74
2 changed files with 181 additions and 46 deletions

View File

@@ -137,10 +137,10 @@ impl<'b> Decoder<'b> {
/// Otherwise we decode an item in the list with the decoder function passed in.
/// Then decode the next bit in the buffer and repeat above.
/// Returns a list of items decoded with the decoder function.
pub fn decode_list_with<T: Decode<'b>>(
&mut self,
decoder_func: for<'r> fn(&'r mut Decoder) -> Result<T, Error>,
) -> Result<Vec<T>, Error> {
pub fn decode_list_with<T: Decode<'b>, F>(&mut self, decoder_func: F) -> Result<Vec<T>, Error>
where
F: Copy + FnOnce(&mut Decoder) -> Result<T, Error>,
{
let mut vec_array: Vec<T> = Vec::new();
while self.bit()? {
vec_array.push(decoder_func(self)?)