use crate::{
decoder::{DecError, Decoder, MeasureBuf},
encoder::{EncError, Encoder, ImprovidentBufMut},
};
pub trait Compact1CodecOpinion<For> {
fn encode<B: ImprovidentBufMut>(
&self,
encoder: &mut Encoder<B>,
what: &For,
) -> Result<(), EncError>
where
Self: Sized;
fn decode<B: MeasureBuf>(&self, decoder: &mut Decoder<B>) -> Result<For, DecError>
where
For: Sized;
}
pub trait Compact1Codec {
fn encode<B: ImprovidentBufMut>(&self, encoder: &mut Encoder<B>) -> Result<(), EncError>
where
Self: Sized;
fn decode<B: MeasureBuf>(decoder: &mut Decoder<B>) -> Result<Self, DecError>
where
Self: Sized;
}
impl<T: Compact1Codec> Compact1CodecOpinion<T> for () {
fn encode<B: ImprovidentBufMut>(
&self,
encoder: &mut Encoder<B>,
what: &T,
) -> Result<(), EncError>
where
Self: Sized,
{
what.encode(encoder)
}
#[inline(always)]
fn decode<B: MeasureBuf>(&self, decoder: &mut Decoder<B>) -> Result<T, DecError>
where
T: Sized,
{
<T as Compact1Codec>::decode(decoder)
}
}