use super::*; /// Inlining version of [`ParseResult`]. Preserves the parser. pub type IParseResult<'a, F, I> = Result<(Mtbl<'a, F>, I), ParseError<'a, F>>; /// For auto-deriving [`InliningFactory`] from concrete implementations. pub trait CInliningFactory<'a, Ctx: Context<'a>>: FactoryBase<'a> + ImplMode { /// Concrete implementation of [`InliningFactory::extension_error`]. fn cextension_error(&self, tail: &[u8]) -> Self::ParseError; /// Concrete implementation of [`InliningFactory::ideserialize`]. fn cideserialize>(&self, inctx: I) -> IParseResult<'a, Self, I>; } /// Factory preserving the parser on success. pub trait InliningFactory<'a, Ctx: Context<'a>>: FactoryBase<'a> + ParseMode { /// Always fail on extension, /// as parsing of an inlining object should be determined without reaching EOF. fn extension_error(&self, tail: &[u8]) -> Self::ParseError; /// Inlining version of [`FactoryParse::deserialize`]. Preserves the parser. fn ideserialize>(&self, inctx: I) -> IParseResult<'a, Self, I>; } impl<'a, Ctx: Context<'a>, F: FactoryModeParse<'a, Ctx> + ParseMode> InliningFactory<'a, Ctx> for F { fn extension_error(&self, tail: &[u8]) -> Self::ParseError { self.mextend((), tail) } fn ideserialize>(&self, inctx: I) -> IParseResult<'a, Self, I> { self.mdeserialize(inctx) } } impl<'a, Ctx: Context<'a>, F: CInliningFactory<'a, Ctx>> FactoryModeProxy<'a, Ctx> for WithMode { type F = F; fn pmdeserialize>(f: &Self::F, inctx: I) -> ModeResultM<'a, F, I> { f.cideserialize(inctx) } fn pmextend( f: &F, _mentionable: ExtensionSourceM<'a, F>, tail: &[u8], ) -> ExtensionResultM<'a, F> { f.cextension_error(tail) } }