use crate::Error;
use std::marker::PhantomData;
pub trait Follow<'a> {
type Inner;
fn follow(buf: &'a [u8], loc: usize) -> Result<Self::Inner, Error>;
}
pub trait FollowBuf {
type Buf: std::convert::AsRef<[u8]>;
type Inner;
fn follow_buf(buf: Self::Buf, loc: usize) -> Result<Self::Inner, Error>;
}
#[allow(dead_code)]
#[inline]
pub fn lifted_follow<'a, T: Follow<'a>>(buf: &'a [u8], loc: usize) -> Result<T::Inner, Error> {
T::follow(buf, loc)
}
#[derive(Debug, Default)]
pub struct FollowStart<T>(PhantomData<T>);
impl<'a, T: Follow<'a> + 'a> FollowStart<T> {
#[inline]
pub fn new() -> Self {
Self { 0: PhantomData }
}
#[inline]
pub fn self_follow(&'a self, buf: &'a [u8], loc: usize) -> Result<T::Inner, Error> {
T::follow(buf, loc)
}
}
impl<'a, T: Follow<'a>> Follow<'a> for FollowStart<T> {
type Inner = T::Inner;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Result<Self::Inner, Error> {
T::follow(buf, loc)
}
}