use crate::{
DecodeError, EncodeError, NestedDecode, NestedDecodeInput, NestedEncode, NestedEncodeOutput,
TopDecode, TopDecodeInput, TopEncode, TopEncodeOutput,
};
use alloc::boxed::Box;
impl<T: TopEncode> TopEncode for &T {
#[inline]
fn top_encode<O: TopEncodeOutput>(&self, output: O) -> Result<(), EncodeError> {
(*self).top_encode(output)
}
#[inline]
fn top_encode_or_exit<O: TopEncodeOutput, ExitCtx: Clone>(
&self,
output: O,
c: ExitCtx,
exit: fn(ExitCtx, EncodeError) -> !,
) {
(*self).top_encode_or_exit(output, c, exit);
}
}
impl<T: TopEncode> TopEncode for Box<T> {
#[inline]
fn top_encode<O: TopEncodeOutput>(&self, output: O) -> Result<(), EncodeError> {
self.as_ref().top_encode(output)
}
#[inline]
fn top_encode_or_exit<O: TopEncodeOutput, ExitCtx: Clone>(
&self,
output: O,
c: ExitCtx,
exit: fn(ExitCtx, EncodeError) -> !,
) {
self.as_ref().top_encode_or_exit(output, c, exit);
}
}
impl<T: TopDecode> TopDecode for Box<T> {
fn top_decode<I: TopDecodeInput>(input: I) -> Result<Self, DecodeError> {
T::top_decode_boxed(input)
}
fn top_decode_or_exit<I: TopDecodeInput, ExitCtx: Clone>(
input: I,
c: ExitCtx,
exit: fn(ExitCtx, DecodeError) -> !,
) -> Self {
T::top_decode_boxed_or_exit(input, c, exit)
}
}
impl<T: NestedEncode> NestedEncode for &T {
#[inline]
fn dep_encode<O: NestedEncodeOutput>(&self, dest: &mut O) -> Result<(), EncodeError> {
(*self).dep_encode(dest)
}
fn dep_encode_or_exit<O: NestedEncodeOutput, ExitCtx: Clone>(
&self,
dest: &mut O,
c: ExitCtx,
exit: fn(ExitCtx, EncodeError) -> !,
) {
(*self).dep_encode_or_exit(dest, c, exit);
}
}
impl<T: NestedEncode> NestedEncode for Box<T> {
#[inline(never)]
fn dep_encode<O: NestedEncodeOutput>(&self, dest: &mut O) -> Result<(), EncodeError> {
self.as_ref().dep_encode(dest)
}
fn dep_encode_or_exit<O: NestedEncodeOutput, ExitCtx: Clone>(
&self,
dest: &mut O,
c: ExitCtx,
exit: fn(ExitCtx, EncodeError) -> !,
) {
self.as_ref().dep_encode_or_exit(dest, c, exit);
}
}
impl<T: NestedDecode> NestedDecode for Box<T> {
fn dep_decode<I: NestedDecodeInput>(input: &mut I) -> Result<Self, DecodeError> {
Ok(Box::new(T::dep_decode(input)?))
}
fn dep_decode_or_exit<I: NestedDecodeInput, ExitCtx: Clone>(
input: &mut I,
c: ExitCtx,
exit: fn(ExitCtx, DecodeError) -> !,
) -> Self {
Box::new(T::dep_decode_or_exit(input, c, exit))
}
}