redoubt_codec_core/collections/
redoubt_option.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 `RedoubtOption<T>`.
6//!
7//! All codec traits simply delegate to the inner `Option<T>` implementation.
8
9use redoubt_alloc::RedoubtOption;
10use redoubt_zero::{FastZeroizable, ZeroizationProbe, ZeroizeMetadata};
11
12use crate::codec_buffer::RedoubtCodecBuffer;
13use crate::error::{DecodeError, EncodeError, OverflowError};
14use crate::traits::{BytesRequired, Decode, Encode};
15
16impl<T> BytesRequired for RedoubtOption<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 Option
23        self.as_option().encode_bytes_required()
24    }
25}
26
27impl<T> Encode for RedoubtOption<T>
28where
29    T: Encode + BytesRequired + FastZeroizable + ZeroizeMetadata + ZeroizationProbe,
30{
31    #[inline(always)]
32    fn encode_into(&mut self, buf: &mut RedoubtCodecBuffer) -> Result<(), EncodeError> {
33        // Delegate to inner Option
34        self.as_mut_option().encode_into(buf)
35    }
36}
37
38impl<T> Decode for RedoubtOption<T>
39where
40    T: Decode + Default + FastZeroizable + ZeroizeMetadata + ZeroizationProbe,
41{
42    #[inline(always)]
43    fn decode_from(&mut self, buf: &mut &mut [u8]) -> Result<(), DecodeError> {
44        // Delegate to inner Option
45        self.as_mut_option().decode_from(buf)
46    }
47}