diff --git a/src/rcore/modes.rs b/src/rcore/modes.rs index da51b34..1bed4aa 100644 --- a/src/rcore/modes.rs +++ b/src/rcore/modes.rs @@ -75,6 +75,42 @@ where type _Mtbl = Self::Mtbl; } +pub type ParseResultM<'a, Ctx, F, I> = + <::Mode as Mode>::ParseResult, ParseError<'a, Ctx, F>, I>; + +pub type ExtensionResultM<'a, Ctx, F> = + <::Mode as Mode>::ExtensionResult, ParseError<'a, Ctx, F>>; + +pub trait FactoryModeParse<'a, Ctx: Context<'a>>: FactoryBase<'a, Ctx> + ParseMode { + fn mdeserialize>(&self, inctx: I) -> ParseResultM<'a, Ctx, Self, I>; + fn mextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ExtensionResultM<'a, Ctx, Self>; +} + +pub trait FactoryModeProxy<'a, Ctx: Context<'a>> { + type F: FactoryBase<'a, Ctx> + ParseMode; + + fn pmdeserialize>(f: &Self::F, inctx: I) + -> ParseResultM<'a, Ctx, Self::F, I>; + fn pmextend( + f: &Self::F, + mentionable: Mtbl<'a, Ctx, Self::F>, + tail: &[u8], + ) -> ExtensionResultM<'a, Ctx, Self::F>; +} + +impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx> + WithParseMode> FactoryModeParse<'a, Ctx> for F +where + F::WithMode: FactoryModeProxy<'a, Ctx, F = F>, +{ + fn mdeserialize>(&self, inctx: I) -> ParseResultM<'a, Ctx, Self, I> { + >::pmdeserialize(self, inctx) + } + + fn mextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ExtensionResultM<'a, Ctx, Self> { + >::pmextend(self, mentionable, tail) + } +} + pub struct RegularMode; impl Mode for RegularMode {