redoubt_codec_core/collections/
redoubt_vec.rs

1// Copyright (c) 2025-2026 Federico Hoerth <memparanoid@gmail.com>
2// SPDX-License-Identifier: GPL-3.0-only
3// See LICENSE in the repository root for full license text.
4
5//! Proxy codec implementation for `RedoubtVec<T>`.
6//!
7//! All codec traits simply delegate to the inner `Vec<T>` implementation.
8
9use redoubt_alloc::RedoubtVec;
10use redoubt_zero::{FastZeroizable, ZeroizationProbe, ZeroizeMetadata};
11
12use crate::codec_buffer::RedoubtCodecBuffer;
13use crate::error::{DecodeError, EncodeError, OverflowError};
14use crate::traits::{BytesRequired, Decode, DecodeSlice, Encode, EncodeSlice, PreAlloc};
15
16impl<T> BytesRequired for RedoubtVec<T>
17where
18    T: BytesRequired + FastZeroizable + ZeroizeMetadata + ZeroizationProbe,
19{
20    #[inline(always)]
21    fn encode_bytes_required(&self) -> Result<usize, OverflowError> {
22        // Delegate to inner Vec
23        self.as_vec().encode_bytes_required()
24    }
25}
26
27impl<T> Encode for RedoubtVec<T>
28where
29    T: EncodeSlice + BytesRequired + FastZeroizable + ZeroizeMetadata + ZeroizationProbe,
30{
31    #[inline(always)]
32    fn encode_into(&mut self, buf: &mut RedoubtCodecBuffer) -> Result<(), EncodeError> {
33        // Delegate to inner Vec
34        self.as_mut_vec().encode_into(buf)
35    }
36}
37
38impl<T> Decode for RedoubtVec<T>
39where
40    T: DecodeSlice + PreAlloc + FastZeroizable + ZeroizeMetadata + ZeroizationProbe,
41{
42    #[inline(always)]
43    fn decode_from(&mut self, buf: &mut &mut [u8]) -> Result<(), DecodeError> {
44        // Delegate to inner Vec
45        self.as_mut_vec().decode_from(buf)
46    }
47}