From 486d7e7af802eef6d3c11fec4c2c30b6d80c9e4c Mon Sep 17 00:00:00 2001 From: timofey Date: Sat, 29 Jul 2023 19:28:44 +0000 Subject: [PATCH] `FactoryParse` via `FactoryModeParse` --- src/rcore/modes.rs | 15 +++++++++------ src/rstd/inlining/modes.rs | 4 ++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/rcore/modes.rs b/src/rcore/modes.rs index 52b0393..7a1b005 100644 --- a/src/rcore/modes.rs +++ b/src/rcore/modes.rs @@ -28,6 +28,8 @@ pub trait Mode { result: Self::ExtensionResult, f: impl FnOnce(A0) -> Result, ) -> Self::ExtensionResult; + + fn xseal(result: Self::ExtensionResult) -> Result; } pub trait ParseMode { @@ -55,16 +57,13 @@ pub trait FactoryProxy<'a, Ctx: Context<'a>> { ) -> ParseResult<'a, Ctx, Self::F>; } -impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx> + WithParseMode> FactoryParse<'a, Ctx> for F -where - F::WithMode: FactoryProxy<'a, Ctx, F = Self>, -{ +impl<'a, Ctx: Context<'a>, F: FactoryModeParse<'a, Ctx>> FactoryParse<'a, Ctx> for F { fn deserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> { - >::pdeserialize(self, inctx) + <::Mode as Mode>::seal(self.mdeserialize(inctx)) } fn extend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> { - >::pextend(self, mentionable, tail) + <::Mode as Mode>::xseal(self.mextend(mentionable, tail)) } } @@ -149,6 +148,10 @@ impl Mode for RegularMode { ) -> Self::ExtensionResult { result.and_then(f) } + + fn xseal(result: Self::ExtensionResult) -> Result { + result + } } pub trait RegularFactory<'a, Ctx: Context<'a>>: diff --git a/src/rstd/inlining/modes.rs b/src/rstd/inlining/modes.rs index 86876fa..e64e66e 100644 --- a/src/rstd/inlining/modes.rs +++ b/src/rstd/inlining/modes.rs @@ -40,6 +40,10 @@ impl Mode for InliningMode { ) -> Self::ExtensionResult { result } + + fn xseal(result: Self::ExtensionResult) -> Result { + Err(result) + } } impl<'a, Ctx: Context<'a>, F: InlineableFactory<'a, Ctx>> FactoryProxy<'a, Ctx>