From 2ea99d3d55d70f24878e3c1ad7b23c21cb540264 Mon Sep 17 00:00:00 2001 From: Anders Trier Olesen Date: Thu, 11 Apr 2024 21:54:31 +0200 Subject: [PATCH] DecoderResult: into_inner_vec --- src/decoder_result.rs | 20 +++++++++++--------- src/engine/shards.rs | 2 +- src/rate/decoder_work.rs | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/decoder_result.rs b/src/decoder_result.rs index 0af46a6..aa4dd66 100644 --- a/src/decoder_result.rs +++ b/src/decoder_result.rs @@ -1,4 +1,5 @@ use crate::rate::DecoderWork; +use std::mem::swap; // ====================================================================== // DecoderResult - PUBLIC @@ -27,6 +28,16 @@ impl<'a> DecoderResult<'a> { pub fn restored_original_iter(&self) -> RestoredOriginal { RestoredOriginal::new(self.work) } + + /// Returns inner Vec + pub fn into_inner_vec(self) -> Vec { + let mut buf = Vec::new(); + swap(&mut buf, &mut self.work.shards.data); + //TODO: truncate + //buf.truncate(self. + self.work.reset_received(); + buf + } } // ====================================================================== @@ -38,15 +49,6 @@ impl<'a> DecoderResult<'a> { } } -// ====================================================================== -// DecoderResult - IMPL DROP - -impl<'a> Drop for DecoderResult<'a> { - fn drop(&mut self) { - self.work.reset_received(); - } -} - // ====================================================================== // RestoredOriginal - PUBLIC diff --git a/src/engine/shards.rs b/src/engine/shards.rs index 4df3911..860f2f1 100644 --- a/src/engine/shards.rs +++ b/src/engine/shards.rs @@ -8,7 +8,7 @@ pub(crate) struct Shards { shard_bytes: usize, // Flat array of `shard_count * shard_bytes` bytes. - data: Vec, + pub(crate) data: Vec, } impl Shards { diff --git a/src/rate/decoder_work.rs b/src/rate/decoder_work.rs index f5145ad..213ba18 100644 --- a/src/rate/decoder_work.rs +++ b/src/rate/decoder_work.rs @@ -23,7 +23,7 @@ pub struct DecoderWork { recovery_received_count: usize, // May contain extra zero bits. received: FixedBitSet, - shards: Shards, + pub(crate) shards: Shards, } impl DecoderWork {