inlining dyn box
This commit is contained in:
parent
c016fa44e6
commit
bab0b4169e
@ -90,16 +90,20 @@ impl<'a: 'c, 'c, Ctx: Context<'a>> InCtx<'a, Ctx> for &'c mut dyn DeCtx<'a, Ctx>
|
||||
|
||||
pub type ResultDyn<A, I> = Result<(A, I), Vec<u8>>;
|
||||
|
||||
pub trait InliningDyn<'c>: 'c {
|
||||
fn idread_n(self, n: usize) -> ResultDyn<Vec<u8>, Box<dyn InliningDyn<'c>>>;
|
||||
pub trait InCtxDyn<'a: 'c, 'c, Ctx: Context<'a>>: 'c {
|
||||
fn idread_n(self, n: usize) -> ResultDyn<Vec<u8>, Box<dyn InCtxDyn<'a, 'c, Ctx>>>;
|
||||
|
||||
fn idread_all(self) -> Vec<u8>;
|
||||
|
||||
fn idtell(&self) -> usize;
|
||||
|
||||
fn idnext_address(self) -> ResultDyn<Address, Box<dyn InCtxDyn<'a, 'c, Ctx>>>;
|
||||
|
||||
fn idresolver(&self) -> Rc<dyn Resolver<'a, Ctx>>;
|
||||
}
|
||||
|
||||
impl<'c, I: 'c + Inlining> InliningDyn<'c> for I {
|
||||
fn idread_n(self, n: usize) -> ResultDyn<Vec<u8>, Box<dyn InliningDyn<'c>>> {
|
||||
impl<'a: 'c, 'c, Ctx: Context<'a>, I: 'c + InCtx<'a, Ctx>> InCtxDyn<'a, 'c, Ctx> for I {
|
||||
fn idread_n(self, n: usize) -> ResultDyn<Vec<u8>, Box<dyn InCtxDyn<'a, 'c, Ctx>>> {
|
||||
let (vec, i) = self.iread_n(n, |slice| Vec::from(slice), |slice| Vec::from(slice))?;
|
||||
Ok((vec, Box::new(i)))
|
||||
}
|
||||
@ -111,16 +115,8 @@ impl<'c, I: 'c + Inlining> InliningDyn<'c> for I {
|
||||
fn idtell(&self) -> usize {
|
||||
self.itell()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait InCtxDyn<'a: 'c, 'c, Ctx: Context<'a>>: InliningDyn<'c> {
|
||||
fn icdnext_address(self) -> ResultDyn<Address, Box<dyn InCtxDyn<'a, 'c, Ctx>>>;
|
||||
|
||||
fn idresolver(&self) -> Rc<dyn Resolver<'a, Ctx>>;
|
||||
}
|
||||
|
||||
impl<'a: 'c, 'c, Ctx: Context<'a>, I: 'c + InCtx<'a, Ctx>> InCtxDyn<'a, 'c, Ctx> for I {
|
||||
fn icdnext_address(self) -> ResultDyn<Address, Box<dyn InCtxDyn<'a, 'c, Ctx>>> {
|
||||
fn idnext_address(self) -> ResultDyn<Address, Box<dyn InCtxDyn<'a, 'c, Ctx>>> {
|
||||
let (address, i) = self.icnext_address(|slice| Vec::from(slice))?;
|
||||
Ok((address, Box::new(i)))
|
||||
}
|
||||
@ -130,6 +126,36 @@ impl<'a: 'c, 'c, Ctx: Context<'a>, I: 'c + InCtx<'a, Ctx>> InCtxDyn<'a, 'c, Ctx>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a: 'c, 'c, Ctx: Context<'a>> Inlining for Box<dyn InCtxDyn<'a, 'c, Ctx>> {
|
||||
fn iread_n<A, E>(
|
||||
self,
|
||||
n: usize,
|
||||
ok: impl FnOnce(&[u8]) -> A,
|
||||
err: impl FnOnce(&[u8]) -> E,
|
||||
) -> Result<(A, Self), E> {
|
||||
let (vec, i) = self.idread_n(n).map_err(|vec| err(&vec))?;
|
||||
Ok((ok(&vec), i))
|
||||
}
|
||||
|
||||
fn iread_all<A>(self, ok: impl FnOnce(&[u8]) -> A) -> A {
|
||||
ok(&self.idread_all())
|
||||
}
|
||||
|
||||
fn itell(&self) -> usize {
|
||||
self.idtell()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a: 'c, 'c, Ctx: Context<'a>> InCtx<'a, Ctx> for Box<dyn InCtxDyn<'a, 'c, Ctx>> {
|
||||
fn icnext_address<E>(self, err: impl FnOnce(&[u8]) -> E) -> Result<(Address, Self), E> {
|
||||
self.idnext_address().map_err(|vec| err(&vec))
|
||||
}
|
||||
|
||||
fn iresolver(&self) -> Rc<dyn Resolver<'a, Ctx>> {
|
||||
self.idresolver()
|
||||
}
|
||||
}
|
||||
|
||||
pub type IParseResult<'a, Ctx, F, I> =
|
||||
Result<(Mtbl<'a, Ctx, F>, I), <F as Factory<'a, Ctx>>::ParseError>;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user