From a5a4cadef61ff94997655488f0a56aec4f8095fd Mon Sep 17 00:00:00 2001 From: timofey Date: Fri, 30 Jun 2023 18:36:09 +0000 Subject: [PATCH] `InCtx::icnext_*` --- src/rstd/inlining.rs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/rstd/inlining.rs b/src/rstd/inlining.rs index 8d82b65..34ab4c9 100644 --- a/src/rstd/inlining.rs +++ b/src/rstd/inlining.rs @@ -34,7 +34,15 @@ impl Inlining for &mut D { } } -pub trait InCtx<'a, Ctx: Context<'a>>: Inlining {} +pub trait InCtx<'a, Ctx: Context<'a>>: Inlining { + fn icnext_address(self, err: impl FnOnce(&[u8]) -> E) -> Result<(Address, Self), E>; + + fn icnext_point<'b, A: Mentionable<'a, Ctx>, E>( + self, + factory: A::Fctr, + err: impl FnOnce(&[u8]) -> E, + ) -> Result<(Point<'a, Ctx, A>, Self), E>; +} struct InCtxT<'a: 'c, 'c, Ctx: Context<'a>> { dectx: &'c mut dyn DeCtx<'a, Ctx>, @@ -62,7 +70,27 @@ impl<'a: 'c, 'c, Ctx: Context<'a>> Inlining for InCtxT<'a, 'c, Ctx> { } } -impl<'a: 'c, 'c, Ctx: Context<'a>> InCtx<'a, Ctx> for InCtxT<'a, 'c, Ctx> {} +impl<'a: 'c, 'c, Ctx: Context<'a>> InCtx<'a, Ctx> for InCtxT<'a, 'c, Ctx> { + fn icnext_address(self, err: impl FnOnce(&[u8]) -> E) -> Result<(Address, Self), E> { + let (addresses, deserialiser, _) = self.dectx.adr(); + match deserialiser.inext_address(addresses, err) { + Ok((address, _)) => Ok((address, self)), + Err(e) => Err(e), + } + } + + fn icnext_point<'b, A: Mentionable<'a, Ctx>, E>( + self, + factory: A::Fctr, + err: impl FnOnce(&[u8]) -> E, + ) -> Result<(Point<'a, Ctx, A>, Self), E> { + let (point, inctx) = self.icnext_address(err)?; + Ok(( + Point::from_address(point, factory, inctx.dectx.resolver()), + inctx, + )) + } +} pub type IParseResult<'a, Ctx, F, I> = Result<(Mtbl<'a, Ctx, F>, I), >::ParseError>;