use std::{convert::Infallible, marker::PhantomData};
use fjall::Slice;
use crate::codec::Decode;
#[derive(Default)]
pub struct LazyDecode<C>(std::marker::PhantomData<C>);
impl<C: 'static> Decode for LazyDecode<C> {
type Item = Lazy<C>;
type Error = Infallible;
fn decode(bytes: fjall::Slice) -> Result<Self::Item, Self::Error> {
Ok(Lazy(bytes, PhantomData))
}
}
#[derive(Debug)]
#[repr(transparent)]
pub struct Lazy<C>(Slice, PhantomData<C>);
impl<C> Clone for Lazy<C> {
fn clone(&self) -> Self {
Self(self.0.clone(), PhantomData)
}
}
impl<C> Lazy<C> {
pub fn remap<NC>(self) -> Lazy<NC> {
Lazy(self.0, PhantomData)
}
}
impl<C: Decode> Lazy<C> {
pub fn decode(self) -> Result<C::Item, C::Error> {
C::decode(self.0)
}
}