use std::marker;
use heed_traits::BoxedError;
#[derive(Default)]
pub struct LazyDecode<C>(marker::PhantomData<C>);
impl<'a, C: 'static> heed_traits::BytesDecode<'a> for LazyDecode<C> {
type DItem = Lazy<'a, C>;
fn bytes_decode(bytes: &'a [u8]) -> Result<Self::DItem, BoxedError> {
Ok(Lazy { data: bytes, _phantom: marker::PhantomData })
}
}
#[derive(Copy, Clone)]
pub struct Lazy<'a, C> {
data: &'a [u8],
_phantom: marker::PhantomData<C>,
}
impl<'a, C: heed_traits::BytesDecode<'a>> Lazy<'a, C> {
pub fn remap<NC>(&self) -> Lazy<'a, NC> {
Lazy { data: self.data, _phantom: marker::PhantomData }
}
pub fn decode(&self) -> Result<C::DItem, BoxedError> {
C::bytes_decode(self.data)
}
}